/** * sum - Sum all of integers read from input. */ // +---------+-------------------------------------------------------- // | Headers | // +---------+ #include // For scanf, printf // +------+----------------------------------------------------------- // | Main | // +------+ int main () { int sum = 0; // The sum of the numbers read so far. int num; // The next number we've read int check; // The result of scanf // Read all the numbers and add them to our sum while ((check = scanf ("%d", &num)) != EOF) { // Special case: Failed to read a number and failed to reach // end of file. if (check == 0) { printf ("Invalid input: '%c'\n", getchar ()); continue; } sum += num; } // while // Print out the result printf ("%d\n", sum); // And we're done return 0; } // main