Write a program to display a
menu for calculating area of
circle or perimeter of circle using
if-else statement.
Answers
Answer:
#include<stdio.h>
#include<conio.h>
void main()
{
int c;
float a,p,r;
printf("\n 1. Area of Circle");
printf("\n 2. Perimeter of Circle");
clrscr();
printf("\n Enter the value of Radius :-");
scanf("%f",&r);
if(c==1)
{
a=3.14*r*r;
printf("\n Area of circle :- %f", a);
}
else
{
p=4*3.14*r;
printf("\n Perimeter of Circle :- %f",p);
}
getch();
}
Here's an example program in Python that displays a menu for calculating the area or perimeter of a circle using if-else statements:
print("Menu:")
print("1. Calculate area of circle")
print("2. Calculate perimeter of circle")
choice = int(input("Enter your choice (1 or 2): "))
if choice == 1:
radius = float(input("Enter the radius of the circle: "))
area = 3.14159 * radius ** 2
print("The area of the circle is", area)
elif choice == 2:
radius = float(input("Enter the radius of the circle: "))
perimeter = 2 * 3.14159 * radius
print("The perimeter of the circle is", perimeter)
else:
print("Invalid choice!")
- This program first displays a menu with two options: to calculate the area or perimeter of a circle.
- It then prompts the user to enter their choice (1 or 2) and uses an if-else statement to perform the appropriate calculation based on the user's choice.
- If the user enters an invalid choice (i.e., a number other than 1 or 2), the program prints an error message.
#SPJ3