0

Write a c program to find average of N numbers using do while

Please explain me this question or program

5th Nov 2018, 2:32 PM
Sree
Sree - avatar
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
5th Nov 2018, 6:16 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 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.
5th Nov 2018, 2:53 PM
Lambda_Driver
Lambda_Driver - avatar
0
Just using do while .no arrays. We are just beginning learners of c and arrays arenot completed in our syllabus
5th Nov 2018, 3:08 PM
Sree
Sree - avatar
0
Anyways thank you for answering and please answer that only using do while
5th Nov 2018, 3:09 PM
Sree
Sree - avatar