Summing integers - compact version
#include <stdio.h> void main() { long sum = 0L; int count = 10; /* The number of integers to be summed */ int i = 0; /* The loop counter */ /* Sum integers from 1 to count */ for (i = 1 ; i<= count ; sum += i++ ); printf("\nTotal of the first %d numbers is %ld\n", count, sum); }
1. | long value array | ||
2. | Choosing the correct type: long | ||
3. | Use nested if to analyze numbers | ||
4. | Read long from keyboard | ||
5. | Convert long to short int |