2. Vishal is having a bunch of coins ranging from rupees 1 to 10. Help him to write program to find the sum and average of the coins that he is having using while loop.
Solution:
#include <stdio.h>
void main() {
int i, sum = 0;
float avg;
for (i = 1; i <= 10; i++) {
sum += i;
}
avg = sum / 10.0;
printf("The sum of 10 coins is : %d\nThe Average is : %f\n", sum, avg);
}
Comments
Leave a comment