Learn about C Program to find Area of Circle Using Pointer in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.
C Program to find Area of Circle Using Pointer
According to the formula , Area of circle is equal to pi multiplied by square of radius. Hence, we assign value of radius to pointer pr, so we can calculate the area and assign to pointer parea.
#include<stdio.h>
#define PI 3.14
int main()
{
double r, area;
double *pr, *parea;
pr= &r, parea=&area;//assigning varaibles to pointers
printf("Enter radius: ");
scanf("%lf",pr);
*parea = PI*(*pr)*(*pr);//calculating area
printf("Area of radius %.3lf = %.3lf\n", *pr, *parea);
return 0;
}
Output:
Enter radius: 21
Area of radius 21.000 = 1384.740
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Codes :
Add two Number Using Pointer & Function in C
C Program to add Two Number Using Pointer