SCHOOL OF CODE BUILDERS
Learn To CODE. Become A DEVELOPER.
Pages
HOME
DATA STRUCTURES
STRINGS
ARRAYS
MATRIX
BINARY TREES
LINKED LIST
STACK
QUEUE
SORTING
SEARCHING
C
PYTHON
PSEUDOCODE
CONTEST PROBLEMS
ALGORITHMS
PATTERNS
PHP
C PUZZLES
C INTERVIEW QUESTIONS
JAVA
C++
HASHING
RECURSION
BASIC C PROGRAMS
TCS-CODEVITA
FACEBOOK
CONTACT US
C program to calculate average of 3 numbers
C program to calculate average of 3 numbers
Output:
Enter the three numbers:
1 2 3
The average of 3 numbers is 2.000000
Implementation:
#include
int main(void) { int n=3; float average; float sum=0,x; int i; printf("Enter the three numbers:\n"); for(i=1;i<=n;i++) { scanf("%f",&x); sum += x; } /* calculating the average sum of elements average = --------------- number of elements */ average = sum / (float)n; printf("The average of %d numbers is %f",n,average); return 0; }
PREVIOUS
NEXT
HOME