Home C Programming Language / Programs / Write a program that asks the user to enter some numbers and then find their average using counter-based loop.
🚀 Programming Example

Write a program that asks the user to enter some numbers and then find their average using counter-based loop.

👁 1,041 Views
💻 Practical Program
📘 Step Learning
Write a program that asks the user to enter some numbers and then find their average using counter-based loop.

💻 Program Code

#include <stdio.h>
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;
}

                        

🖥 Program Output

<b>Output 1:</b>

 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
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.