write a C++ program to find area of a circle and triangle
Answers
Solution:
The given codes are written in CPP.
1. Area of a circle.
#include <iostream>
using namespace std;
int main() {
float rad, area;
cout << "Enter radius of the circle: ";
cin >> rad;
area = 3.14 * rad * rad;
cout << "Area of the triangle is " << area << " square unit.";
return 0;
}
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
2. Area of a triangle.
#include <iostream>
using namespace std;
int main() {
float height, base, area;
cout << "Enter height: ";
cin >> height;
cout << "Enter base: ";
cin >> base;
area = 0.5 * height * base;
cout << "Area of the triangle is " << area << " square unit.";
return 0;
}
Logic:
To calculate area of circle :-
(1) Accept the value of radius from user.
(2) Using formula Area = πr², calculate the area and store the result in a variable. Take π = 3.14
(3) Display the area of the circle.
To calculate area of triangle :-
(1) Accept the values of height and base from user.
(2) Using formula Area = bh/2, calculate the area and store the result in a variable.
(3) Display the area of the triangle.
Refer to the attachment for output.