fork download
  1. #include <stdio.h>
  2.  
  3. /* This function will return a value of type float to any function */
  4. /* that calls it. It will work for all integer or float values */
  5. /* but the result returned will be in the format of float */
  6. float square (float number)
  7. {
  8. float square_value; /* a local variable to hold the result of the number being squared */
  9.  
  10. /* square the number and store it in square_value */
  11. square_value = number * number;
  12.  
  13. return (square_value); /* return this value back to the function that called it */
  14.  
  15. }
  16.  
  17. int main ()
  18. {
  19.  
  20. float value1; /* a local variable to hold a number to be entered */
  21.  
  22. float answer; /* a local variable that holds the value returned from the square function */
  23.  
  24. /* Prompt the user for a number to be squared */
  25. printf ("\nEnter a number: ");
  26. scanf ("%f", &value1);
  27.  
  28. /* Pass value1 to the square function, process it and return the */
  29. /* the squared value into the answer local variable */
  30. answer = square ( value1 );
  31.  
  32. printf ("\nThe square of %5.2f is %8.2f \n", value1, answer);
  33.  
  34. return (0);
  35.  
  36. }
  37.  
  38.  
Success #stdin #stdout 0.01s 5288KB
stdin
5
stdout
Enter a number: 
The square of  5.00 is    25.00