home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / ctutor2.zip / SUMSQRES.C < prev    next >
Text File  |  1989-11-10  |  1KB  |  51 lines

  1.                                           /* Chapter 5 - Program 1 */
  2. int sum; /* This is a global variable */
  3.  
  4. main()
  5. {
  6. int index;
  7.  
  8.    header();        /* This calls the function named header */
  9.    for (index = 1;index <= 7;index++)
  10.      square(index); /* This calls the square function */
  11.    ending();        /* This calls the ending function */
  12. }
  13.  
  14. header()        /* This is the function named header */
  15. {
  16.    sum = 0;     /* Initialize the variable "sum" */
  17.    printf("This is the header for the square program\n\n");
  18. }
  19.  
  20. square(number)   /* This is the square function */
  21. int number;
  22. {
  23. int numsq;
  24.  
  25.    numsq = number * number;  /* This produces the square */
  26.    sum += numsq;
  27.    printf("The square of %d is %d\n",number,numsq);
  28. }
  29.  
  30. ending()   /* This is the ending function */
  31. {
  32.    printf("\nThe sum of the squares is %d\n",sum);
  33. }
  34.  
  35.  
  36.  
  37. /* Result of execution
  38.  
  39. This is the header for the square program
  40.  
  41. The square of 1 is 1
  42. The square of 2 is 4
  43. The square of 3 is 9
  44. The square of 4 is 16
  45. The square of 5 is 25
  46. The square of 6 is 36
  47. The square of 7 is 49
  48.  
  49. The sum of the squares is 140
  50.  
  51. */