home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource4 / 253_01 / squares.c < prev    next >
Encoding:
Text File  |  1990-02-15  |  893 b   |  46 lines

  1.                                           /* Chapter 5 - Program 2 */
  2. main()  /* This is the main program */
  3. {
  4. int x,y;
  5.  
  6.    for(x = 0;x <= 7;x++) {
  7.       y = squ(x);  /* go get the value of x*x */
  8.       printf("The square of %d is %d\n",x,y);
  9.    }
  10.  
  11.    for (x = 0;x <= 7;++x)
  12.       printf("The value of %d is %d\n",x,squ(x));
  13. }
  14.  
  15. squ(in)  /* function to get the value of in squared */
  16. int in;
  17. {
  18. int square;
  19.  
  20.    square = in * in;
  21.    return(square);  /* This sets squ() = square */
  22. }
  23.  
  24.  
  25.  
  26. /* Result of execution
  27.  
  28. The square of 0 is 0
  29. The square of 1 is 1
  30. The square of 2 is 4
  31. The square of 3 is 9
  32. The square of 4 is 16
  33. The square of 5 is 25
  34. The square of 6 is 36
  35. The square of 7 is 49
  36. The value of 0 is 0
  37. The value of 1 is 1
  38. The value of 2 is 4
  39. The value of 3 is 9
  40. The value of 4 is 16
  41. The value of 5 is 25
  42. The value of 6 is 36
  43. The value of 7 is 49
  44.  
  45. */
  46.