home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / GENCSRC.ZIP / FLOATSQ2.C < prev    next >
C/C++ Source or Header  |  1987-11-21  |  847b  |  39 lines

  1.                                          /* Chapter 5 - Program 7 */
  2. #include "stdio.h"   /* Prototypes for standard Input/Outputs     */
  3.  
  4. float sqr(float inval);
  5. float glsqr(void);
  6.  
  7. float z;   /* This is a global variable */
  8.  
  9. main()
  10. {
  11. int index;
  12. float x,y;
  13.  
  14.    for (index = 0;index <= 7;index++){
  15.       x = index;  /* convert int to float */
  16.       y = sqr(x); /* square x to a floating point variable */
  17.       printf("The square of %d is %10.4f\n",index,y);
  18.    }
  19.  
  20.    for (index = 0; index <= 7;index++) {
  21.       z = index;
  22.       y = glsqr();
  23.       printf("The square of %d is %10.4f\n",index,y);
  24.    }
  25. }
  26.  
  27. float sqr(float inval)  /* square a float, return a float */
  28. {
  29. float square;
  30.  
  31.    square = inval * inval;
  32.    return(square);
  33. }
  34.  
  35. float glsqr(void)    /* square a float, return a float */
  36. {
  37.    return(z*z);
  38. }
  39.