Problem In Hand
C program to take input for 3 numbers calculate and print their sum, product and average
The above program can be solved in following ways:Without using function
Using functions with out passing arguments
Using function by passing arguments
Process and Solution Of Problem
Take input for three number and store them in three variables
calculate and store sum in a variable.
calculate and store product in another variable.
calculate and store average in another variable.
further display sum , product and average
Program/Source Code
Solution without functions
#include <stdio.h> int main() { float a,b,c,s,p,av; printf("Enter 3 number "); scanf("%f %f %f",&a,&b,&c); s=a+b+c; p=a*b*c; av=(a+b+c)/3; printf("Sum = %f prod = %f Avg = %f\n",s,p,av);; return 0; }
Output:
Enter 3 number 14
25
63
Sum = 102.000000 prod = 22050.000000 Avg = 34.000000
Solution using functions without arguments
#include <stdio.h> void avg() { float a,b,c,s,p,av; printf("Enter 3 number "); scanf("%f %f %f",&a,&b,&c); s=a+b+c; p=a*b*c; av=(a+b+c)/3; printf("Sum = %f prod = %f Avg = %f\n",s,p,av);; } int main() { avg(); return 0; }
Output:
Enter 3 number 25
96
35
Sum = 156.000000 prod = 84000.000000 Avg = 52.000000
Solution using functions with arguments
#include <stdio.h> void avg(float a,float b,float c) { float s,p,av; s=a+b+c; p=a*b*c; av=(a+b+c)/3; printf("Sum = %f prod = %f Avg = %f\n",s,p,av);; } int main() { float a,b,c; printf("Enter 3 number "); scanf("%f %f %f",&a,&b,&c); avg(a,b,c); return 0; }
Output:
Enter 3 number 74
36
25
Sum = 135.000000 prod = 66600.000000 Avg = 45.000000
You May Also Like:
C Program to find largest of 3 numbers
C Program to print table of a number
C program to check number is +ve, -ve or zero
C program to check number is prime number or not
C program to convert total inches to feet and inches.
<<< Previous: Sum Of Two Numbers | Product Of Three Number : Next >>> |
Tutorials | Technical Questions | Interview Questions |
---|---|---|
C Programming C++ Programming Class 11 (Python) Class 12 (Python) |
C Language C++ Programming Python |
C Interview Questions C++ Interview Questions |