/* Example 1.3 from page 1.3 of Burkhard: Demonstrate simple features of C */
/* Authors: dick (Dick Botting) */
/* Output: Sums of integers from 1 to z, with z = 1,2,3,4,5,6,7*/
/* History: Started Sep 24th 88
Inspected sep 26 by cs290 class
Compiled and run ok sep 26
*/
#include
int z; /*counts from 1 to 7*/
main()
{
z=1;
while( z <= 7 ) {
printf( "%2d%7d\n", z, sum(z));
z=z+1;
}
}
int sum(j) /*returns the sum of 1,2,3,...,j*/
int j; /*last integer to be included in sum*/
{
int i, /* counts from 1 to j*/
x; /* accumulates the sum*/
x=0;
for ( i=1; i<=j; i=i+1)x=x+i;
return x;
}