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
C program to calculate average
Output:
How many numbers: 5
Enter the numbers:
1 2 3 4 5
The average of 5 numbers is 3.000000
Implementation:
#include
int main(void) { int n; float average; float sum=0,x; int i; printf("How many numbers:\n"); scanf("%d",&n); printf("Enter the 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