Write a program using array that asks user to input 10 numbers, then calculates
ID: 3534192 • Letter: W
Question
Write a program using array that asks user to input 10 numbers, then calculates the average of those numbers and finds out the total number that is greater or equal to the average. For example, the user inputs following ten numbers: 1,2 3,4,5, -1, -3,-5,0,4. The sum will be 10, the average is 1. The total number that is greater or equal to 1 is 6 (they are 1,2,3,4,5,4). You have to use the loop structure for this problem. ONLY CAN USE STDIO.H AND STDLIB.H. No Iostream. This is C++ and compiled in DevC++Explanation / Answer
#include<stdio.h>
main()
{
int arr[10];
int i;
int sum=0;
float avg;
int count=0;
printf("Enter 10 nos.: ");
for(i=0;i<10;i++)
{
scanf("%d",arr[i];
sum+=arr[i]
}
avg=sum/10;
printf("Average is %f",avg);
for(i=0;i<10;i++)
{
if(arr[i]>=avg)
{ printf(" %d is greater than %f",arr[i],avg);
count++;}
}
printf("total number greater than average is %d",count);
system("pause");
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.