Solved Examples · Example 19
Q.Write a C program to accept the radius of a circle and compute the area and its perimeter.
The textbook presents this worked program, transcribed exactly as printed (including its printed errors):
#include<stdio.h>
void main()
{
float radius, perimeter, PI=3.142, Area;
printf("Enter the radius\n");
scanf("%f", &radius);
area=PI*radius*radius;
pmeter=2.0*PI*radius;
printf("Area of the circle=%5.2f\n", area);
printf("Perimeter=%5.2f\n", pmeter);
}
Sample output printed in the textbook:
Enter the radius
2.4
Area of the circle = 18.09
Perimeter = 15.08
#include<stdio.h>
void main()
{
float radius, perimeter, PI=3.142, Area;
printf("Enter the radius\n");
scanf("%f", &radius);
area=PI*radius*radius;
pmeter=2.0*PI*radius;
printf("Area of the circle=%5.2f\n", area);
printf("Perimeter=%5.2f\n", pmeter);
}
Enter the radius
2.4
Area of the circle = 18.09
Perimeter = 15.08
Karnataka PUCTextbookLongImportance★★★★★est
60% · 92/154 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →[!TLDR]
Area = PIrr and perimeter = 2PIr; for r = 2.4 with PI = 3.142 they are 18.10 and 15.08.
A named constant, PI = 3.142, keeps the value in one place and makes the two formulas readable. The area uses PIradiusradius and the circumference (called the perimeter here) uses 2.0PIradius. All quantities are float, and %5.2f prints each result in a 6-character field with two decimal places. …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.