Write a program to calculate the area of a circle, rectangle, square using function
#include<stdio.h> #define pi 3.14159 float circle(float); float rectangle(float,float); float square(float); int main() { float r,l,b,sql; printf("Enter radius of a circle: \n"); scanf("%f",&r); printf("Enter two sides of the rectangle: \n"); scanf("%f%f",&l,&b); printf("Enter the length of the square: \n"); scanf("%f",&sql); printf("The Area of a circle is %f\n",circle(r)); printf("The Area of the rectangle is %f\n",rectangle(l,b)); printf("The Area of Square is %f",square(sql)); return 0; } float circle(float r) { return pi*r*r; } float rectangle(float l, float b) { return l*b; } float square(float l) { return l*l; }
Output
Enter radius of circle:
2
Enter two sides of the rectangle:
3
4
Enter the length of the square:
2
The area of a circle is 12.566360
The area of the rectangle is 12.000000
The area of Square is 4.000000