Code:
#include "stdafx.h"
#include <conio.h>
int _tmain(int argc, _TCHAR* argv[])
{
int x;
int XCount;
int sum;
float average;
sum = 0;
XCount = 1;
printf( "Enter Integer 1:" );
scanf_s("%d", &x);
while ( x != 0 ){
sum = sum + x;
XCount = XCount + 1;
printf("Enter Integer %d:", XCount);
scanf_s("%d", &x);
}
if (XCount != 1 ){
average = ( float ) sum / (XCount - 1 );
printf( "*****************\n" );
printf( "You have entered %d non-zero numbers\n", XCount - 1);
printf( "The sum of these integers is %d\n", sum );
printf( "The average of these integers is %.2f\n", average );
printf( "*****************" );
}
else{
printf( "*****************\n" );
printf( "You have entered %d non-zero numbers\n", XCount - 1);
printf( "The sum of these integers is 0\n");
printf( "The average of these integers is 0\n");
printf( "*****************" );
}
getch();
return 0;
}