Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Write a function that computes the square of a given floating-point number a

ID: 3915113 • Letter: C

Question

C++ Write a function that computes the square of a given floating-point number and returns its value. Separate the declaration of the function from its full definition. Write a code to test it with some values. Do not limit yourself only to those values we have given you. #include <stdio.h> /* your code */ int main() { /* your code */ return 0; } /* your code */ Example output square of 2.00 is 4.00 square of 6.00 is 36.00 square of 2.50 is 6.25 square of 12.12 is 146.89 square of 345.68 is 119493.29

Explanation / Answer

#include float square(float n); int main() { printf("square of %.2f is %.2f ", 2.0, square(2)); printf("square of %.2f is %.2f ", 6.0, square(6)); printf("square of %.2f is %.2f ", 2.5, square(2.5)); printf("square of %.2f is %.2f ", 12.12, square(12.12)); printf("square of %.2f is %.2f ", 345.68, square(345.68)); return 0; } float square(float n) { return n*n; }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote