/* * Example of the while statement * * sums a series of numbers, 0 to terminate * */ #include int main(void) { double x, sum; printf("This program sums a series of numbers.\n"); printf("Enter numbers (0 to terminate):"); sum = 0.0; scanf("%lf",&x); while ( x != 0.0 ){ sum += x; scanf("%lf",&x); } printf("The sum is %.4f",sum); return 0; } // note that there are two identical calls of scanf, which is // often hard to avoid when using the while loop