home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / GENCSRC.ZIP / FLOATSQ.C < prev    next >
C/C++ Source or Header  |  1987-11-21  |  746b  |  35 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.