0
Write a c program to find average of N numbers using do while
Please explain me this question or program
4 ответов
+ 7
#include <stdio.h>
int main()
{
int num = 0, count = 0, sum = 0;
do
{
printf("Enter a number: ");
scanf("%d", &num);
printf("\n");
if(num != 0)
{
sum += num;
count++;
}
else
break;
}while(1);
double avg = sum / count;
printf("Avg of numbers is: %f\n", avg);
return 0;
}
Program will keep taking inputs until you don't give it zero.
Means 0 is the terminating condition
+ 2
N = how many numbers needs to be calculated
You can ask input from the user to get how many numbers needs to be calculated and create an array corresponding to that length. You can also have an array already containing the values.
You just need loop through the array to get the average of the numbers.
0
Just using do while .no arrays. We are just beginning learners of c and arrays arenot completed in our syllabus
0
Anyways thank you for answering and please answer that only using do while