At first - I an non english speaker, so I might make some mistakes. And secondly - this program should be working now fine:
Code:
/* Chapter 5 - Program 1 - SUMSQRES.C */
#include <stdio.h>
int sum; /* This is a global variable */
void header (void); // You should write function headers if you use it before defining
void square (int); // I guess you programmed in Pascal before
void ending (void); // Here, in C, you must always define the return type of a function
int main()
{
int index;
header(); /* This calls the function named header */
for (index = 1 ; index <= 7 ; index++)
square(index); /* This calls the square function */
ending(); /* This calls the ending function */
return 0;
}
void header() /* This is the function named header */
{
sum = 0; /* Initialize the variable "sum" */
printf("This is the header for the square program\n\n");
}
void square(int number) /* This is the square function */
//int number; This line was not correct I think.
{
int numsq;
numsq = number * number; /* This produces the square */
sum += numsq;
printf("The square of %d is %d\n", number, numsq);
}
void ending() /* This is the ending function */
{
printf("\nThe sum of the squares is %d\n", sum);
}