6. Program to find the average of three numbers with input values as integer and output value (avg) as float
#include<stdio.h>#include<conio.h> // Linux user - Remove this int main() { int a, b, c; float avg; printf("Enter any three numbers "); scanf("%d %d %d", &a, &b, &c); avg = ( (float)a + (float)b + (float)c ) / 3; /* we have type casted integer to float as a, b, c, 3 all are integer type and
integer / integer gives the result integer. */
printf("Average=%f", avg); getch();// Linux user - Remove this return 0; }
7. Program to find the area of a right angled triangle based on base and height values
#include<stdio.h>#include<conio.h> // Linux user - Remove this int main() { float h, b, area; printf("Enter base "); scanf("%f",&b); printf("Enter height "); scanf("%f", &h); area=(0.5)*b*h; printf("Area of right angled triangle= %f", area); getch(); // Linux user - Remove this return 0; }
8. Program to find or obtain the sum of square of two floating point numbers
#include<stdio.h>#include<conio.h> // Linux user - Remove this int main() { float a, b, sum; printf("Enter first number "); scanf("%f", &a); printf("Enter second number "); scanf("%f", &b); printf("Square of first number = %f", a*a); printf("\n Square of second number = %f", b*b); sum = (a*a + b*b); printf("\n Sum of square = %f", sum); getch(); // Linux user - Remove this return 0; }
9. Program to find the simple interest and total amount based on interest
#include<stdio.h>#include<conio.h> // Linux user - Remove this int main() { /* Variables for principal amount, rate of interest, time duration, simple interest and total amount */ int pa, ri, t, si,ta; // Inputting values printf("Enter principal amount:"); scanf("%d", &pa); printf("Enter rate of interest:"); scanf("%d", &ri); printf("Enter time duration:"); scanf("%d", &t); // calculating simple interest and total amount si = (pa*ri*t)/100; ta = si + pa; // displaying simple interest and total amount printf("Simple interest: %d and total amount: %d", si,ta); getch(); // Linux user - Remove this
return 0; }
10. Program to enter 10 digit number and displaying it in the given format where first 3 digit refer to area code, next three digit to exchange code and remaining to number.Program to enter 10 digit number and displaying it in the given format where first 3 digit refer to area code, next three digit to exchange code and remaining to number.
/*
Input/output:
Enter 10 digit number: 9876543210
You entered: 9876543210
Area code: 987
Exchange code: 654
Number: 3210
The complete telephone number: (987)654-3210
*/
#include<stdio.h>#include<conio.h> // Linux user - Remove this int main() { int a,b,c; // Inputting Telephone number printf("Enter ten digit telephone no."); scanf("%3d %3d %4d",&a,&b,&c); // Displaying telephone number in given format printf("You entered:%d%d%d\n",a,b,c); printf("Area code:%d\n",a); printf("Exchange code:%d\n",b); printf("Number:%d\n",c); printf("The complete telephone number:(%d)%d-%d",a,b,c); getch(); // Linux user - Remove this return 0; }