Home / Programs / Write a program to returning more than one value from a function.
Programming Example

Write a program to returning more than one value from a function.

👁 938 Views
💻 Practical Program
📘 Step by Step Learning
Write a program to returning more than one value from a function.

Program Code

#include"stdio.h"
int main()
{
	float r, area, perimeter;
	float compute(float,float*);
	printf("\n enter the radius of the circle:");
	scanf("%f",&r);
	area=compute(r, &perimeter);
	printf("\n AREA = %f", area);
	printf("\n PERIMETER = %f", perimeter);
	return 0;
}
float compute(float r, float *p)
{
	float a;
	a=(float)3.1415 * r * r;
	*p=(float)3.1415 * 2 * r;
	return a;
}

Output

 enter the radius of the circle:5

 AREA = 78.537506
 PERIMETER = 31.415001
 

Explanation

None

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.