#include <stdio.h> #include <stdlib.h> #define CUBE(x) ((x)*(x)*(x)) int main(void) { int i1, running_sum=0; i1=1; while (i1<=10) { // running_sum=running_sum+CUBE(i1) running_sum+=CUBE(i1); printf("%2d : cube= %4d ; running_sum= %4d\n", i1, CUBE(i1) , running_sum); ++i1; } return 0; }
The above program computes and displays cubes and sums of cubes of the first 10 integers. This program also illustrates the use of while loop.
running_sum=running_sum+CUBE(i1)
e.g. for i1=1 the running_sum=0+1=1, for i2=2 the running_sum=1+8=9
The output is: