Write a program that asks the user to enter some numbers and then find their average using counter-based loop.
C Programming Language Loop control in C Language (Article) Loop control in C Language (Program)
957Program:
#include int main() { int n, a, c=1,s=0; float avg; printf("\n HOW MANY NUMBERS?"); scanf("%d", &n); while(c<=n) { printf("\n Enter the number: "); scanf("%d", &a); s+=a; c++; } avg=(float)s/n; printf(" \n AVERAGE IS %f ", avg); getch(); return 0; }
Output:
Output 1: HOW MANY NUMBERS?5 Enter the number: 1 Enter the number: 2 Enter the number: 3 Enter the number: 4 Enter the number: 5 AVERAGE IS 3.000000
Explanation:
None
This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.