Thu Nov 13, 2008 1:55 pm
#include <stdio.h>
main()
{
int cnt = 0, /* Count of numbers read. */
tot = 0; /* Total of numbers read. */
/* Read until a read fails. */
int num;
while(scanf("%d", &num) == 1) {
tot = tot + num;
cnt = cnt + 1;
}
/* Print the average. */
if(cnt)
printf("Average is %g\n", (double)tot / (double)cnt);
else
printf("No numbers.\n");
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.