Object
Write a program to calculate the area of triangle, volume of sphere and arrange the resultant values in ascending order.
Algorithm
- Declare float variables a, b, r, t and s.
- Read a, b and r.
- Set Area of Triangle t = (1/2)ab.
Area of Sphere s = (4/3)πr3. - IF t < s, then
- Write t, s.
- ELSE
- Write s, t.
- [End of IF-ELSE structure.]
- Exit.
Flowchart

C++ Source Code
// program 20
#include <iostream>
#include <cmath>
#define pi 3.1415927
using namespace std;
int main()
{
float a, b, r, t, s;
cout << "Enter the value for Altitude of a Triangle: ";
cin >> a;
cout << "Enter the value for Base of a Triangle: ";
cin >> b;
cout << "Enter the value for Radius of a Sphere: ";
cin >> r;
t = (1.0 / 2.0) * (a * b);
s = (4.0 / 3.0) * pi * pow(r, 3);
if (t < s)
{
cout << "\n\nArea of Triangle = " << t;
cout << "\nArea of Sphere = " << s;
}
else
{
cout << "\n\nArea of Sphere = " << s;
cout << "\nArea of Triangle = " << t;
}
return 0;
}
C Source Code
/*program 20*/
#include<stdio.h>
#include<math.h>
#define pi 3.1415927
int main()
{
float a, b, r, t, s;
printf("\nEnter the value for Altitude of a Triangle. ");
scanf("%f", &a);
printf("\nEnter the value for Base of a Triangle. ");
scanf("%f", &b);
printf("\nEnter the value for Radius of a Sphere. ");
scanf("%f", &r);
t=(1.0/2.0)*(a*b);
s=(4.0/3.0)*pi*pow(r,3);
if (t<s)
{
printf("\n\nArea of Triangle = %.2f",t);
printf("\nArea of Sphere = %.2f",s);
}
else
{
printf("\n\nArea of Sphere = %.2f",s);
printf("\nArea of Triangle = %.2f",t);
}
return 0;
}
Output
Enter the value for Altitude of a Triangle: 3.65
Enter the value for Base of a Triangle: 4.98
Enter the value for Radius of a Sphere: 9.29
Area of Triangle = 9.0885
Area of Sphere = 3358.43
