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

  1.                                          /* Chapter 5 - Program 3 */
  2. float z;   /* This is a global variable */
  3.  
  4. main()
  5. {
  6. int index;
  7. float x,y,sqr(),glsqr();
  8.  
  9.    for (index = 0;index <= 7;index++){
  10.       x = index;  /* convert int to float */
  11.       y = sqr(x); /* square x to a floating point variable */
  12.       printf("The square of %d is %10.4f\n",index,y);
  13.    }
  14.  
  15.    for (index = 0; index <= 7;index++) {
  16.       z = index;
  17.       y = glsqr();
  18.       printf("The square of %d is %10.4f\n",index,y);
  19.    }
  20. }
  21.  
  22. float sqr(inval)  /* square a float, return a float */
  23. float inval;
  24. {
  25. float square;
  26.  
  27.    square = inval * inval;
  28.    return(square);
  29. }
  30.  
  31. float glsqr()    /* square a float, return a float */
  32. {
  33.    return(z*z);
  34. }
  35.  
  36.  
  37.  
  38. /* Result of execution
  39.  
  40. The square of 0 is      0.0000
  41. The square of 1 is      1.0000
  42. The square of 2 is      4.0000
  43. The square of 3 is      9.0000
  44. The square of 4 is     16.0000
  45. The square of 5 is     25.0000
  46. The square of 6 is     36.0000
  47. The square of 7 is     49.0000
  48. The square of 0 is      0.0000
  49. The square of 1 is      1.0000
  50. The square of 2 is      4.0000
  51. The square of 3 is      9.0000
  52. The square of 4 is     16.0000
  53. The square of 5 is     25.0000
  54. The square of 6 is     36.0000
  55. The square of 7 is     49.0000
  56.  
  57. */
  58.