home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Devil's Doorknob BBS Capture (1996-2003)
/
devilsdoorknobbbscapture1996-2003.iso
/
Dloads
/
OTHERUTI
/
TCPP10-7.ZIP
/
EXAMPLES.ZIP
/
INTRO15.C
< prev
next >
Wrap
Text File
|
1990-09-26
|
756b
|
31 lines
/* INTRO15.C--Example from Chapter 4 of Getting Started */
#include <stdio.h>
int main()
{
char inbuf[130];
int number; /* Number entered by user */
int total = 0; /* Total of numbers entered so far */
int count = 1; /* Count of numbers entered */
printf("Enter 0 to quit\n");
/* Priming statement puts a value into number */
gets(inbuf);
sscanf(inbuf, "%d", &number);
while (number != 0)
{
total += number;
gets(inbuf);
sscanf(inbuf, "%d", &number);
if(number == 0)
printf("Thank you. Ending routine.\n");
else count++;
}
printf("Total is %d\n", total);
printf("Average is %d\n", total / count);
return 0;
}