#include <stdio.h>
#include <conio.h>
int main()
{
int val = 0, count = 0;
float sum = 0, avg = 0;
printf("Enter zero after entering all digits to get
average.\n\n");
do
{
printf("Please enter the %d digit:
",count +1);
scanf("%d",&val);
/*adding values if they are greater than zero*/
if(val > 0)
{
sum = sum + val;
}
else
{
break;
}
/*counting entered digits*/
count++;
}
while(val > 0);
/*printing results*/
if (val == 0 && count != 0)
{
printf("\nSum of entered digits is:
%f\n",sum);
printf("\nTotal number of digits
entered are: %d\n",count);
avg =
sum/count;
printf("\nThe average of entered digits
is: %f\n",avg);
}
else if (val == 0
&& count == 0)
{
printf("\nNo average!");
}
else
printf("\nError");
getche();
return 0;
}
No comments:
Post a Comment