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

The value returned by the function should fit into the right context, in the env

ID: 669997 • Letter: T

Question

The value returned by the function should fit into the right context, in the environment to which the value is returned. What is happening in your example is that the value is returned, but simply discarded.  Could you please rewrite the way you call the function from Main?

C code:

#include <stdio.h>

float myfunc(int r)

{

return (float)3.14 * (r*r) ;

}

int main()

{

int r;

printf("Enter Radius(integer): ");

scanf("%d",&r);

printf("Area of Circle is : %.2f",myfunc(r) );

return 0;

}

Pseudocode:

// This program will calculate the area of a circle

//Start Main Program

Main

// Declare variables

   Declare radius as Integer

   Declare area as float

//Declare intergers

// myfunc Function

myfunc(r):

   return 3.14*r*r

// Main Function

Main:

   print "Enter Radius (Integer) : "

   input r

   print "Area of Circle "

   myfunc(r);

Explanation / Answer

#include <stdio.h>

float myfunc(int r)

{

return (float)3.14 * (r*r) ;

}

int main()

{

int r;

float area;

printf("Enter Radius(integer): ");

scanf("%d",&r);

area = myfunc(r);

printf("Area of Circle is : %.2f",area );

return 0;

}