Problem In Hand
C Program to calculate and print area and circumference of circle
The above program can be solved in following ways:Without using function
Using functions with out passing arguments
Using function by passing arguments
Process and Solution Of Problem
Take input for radius of rectangle and store in variables
calculate and store area of circle in a variable.
calculate and store circumference of circle in another variable.
further display area and circumference
Program/Source Code
Solution without functions
#include <stdio.h> #define pi 3.1415 int main() { float r,a,c; printf("Enter radius of circle "); scanf("%f",&r); a=pi*r*r; c=2*pi*r; printf("Area = %f\n",a); printf("Circumference = %f\n",c); return 0; }
Output:
case 1:
Enter radius of circle 2.3
Area = 16.618534
Circumference = 14.450900
case 2:
Enter radius of circle 5.2
Area = 84.946152
Circumference = 32.671600
Solution using functions without arguments
#include <stdio.h> #define pi 3.1415 void circle() { float r,a,c; printf("Enter radius of circle "); scanf("%f",&r); a=pi*r*r; c=2*pi*r; printf("Area = %f\n",a); printf("Circumference = %f\n",c); } int main() { circle(); return 0; }
Output:
Enter radius of circle 25.3
Area = 2010.842651
Circumference = 158.959900
Solution using functions with arguments
#include <stdio.h> #define pi 3.1415 void circle(float r) { float a,c; a=pi*r*r; c=2*pi*r; printf("Area = %f\n",a); printf("Circumference = %f\n",c); } int main() { float r; printf("Enter radius of circle "); scanf("%f",&r); circle(r); return 0; }
Output:
Enter radius of circle 14.3
Area = 642.405334
Circumference = 89.846901
You May Also Like:
C Program to find largest of 3 numbers
C Program to print table of a number
C program to check number is +ve, -ve or zero
C program to check number is prime number or not
C program to convert total inches to feet and inches.
<<< Previous: Sum Of Two Numbers | Product Of Three Number : Next >>> |
Tutorials | Technical Questions | Interview Questions |
---|---|---|
C Programming C++ Programming Class 11 (Python) Class 12 (Python) |
C Language C++ Programming Python |
C Interview Questions C++ Interview Questions |