#include <stdio.h> #include <stdlib.h> /* Puzzle L15 -- For each integer N from 1 to 25 compute | and print the sum 1+2+...+N | */ int main() { int N = 25; /* line number */ int sum=0; /* Sum */ int j; /* values 1..25 to add to the sum */ printf( "N \t Sum\n"); for (j=1; j<=N; j++) { sum += j; printf("%d \t %d\n", j, sum ); } return 0; }
The not-smart way to do this is to computed each sum individually in a loop for each value of j
.