1.2. Repetition Example
sum.c
#include <stdio.h> int main( void) { int i, sum; i = 1; sum = 0; // initialize while( i <= 100) // ok for i = 1,2,...,100 { sum += i; // add to sum ++i; // increment i } printf( "sum = %i\n", sum); return 0; } /* sample run: sum = 5050 */ |
Flowchart with loop (while) |