Sample C++ program for calculating area of triangle and circle

Sample C++ program for calculating area of triangle and circle

#include<stdio.h>
int main()
{
    int n; //for what user enters
    float h;
    float w;
    float r;
    float area;
    printf("Press 1 to calculate triangle, press 2 for circle.");
    scanf("%i",&n); //store what the user enters into a variable
    if (n == 1)
    {
    printf("Enter height of the right angled triangle : ");
    scanf("%f",&h);
    printf("Enter base of the right angled triangle : ");
    scanf("%f",&w);
    area = 0.5 * h * w;
    printf("Area of right angled triangle is: %.0f",area);
    }
    else
    {
 
    printf("Enter the radius of the circle : ");
    scanf("%f",&r);
    area = 3.14159 * r * r;
    printf("Area of circle is: %.0f",area);
 
    }
    printf("\nPress 1 to restart, press 2 to end.");
    scanf("%i",&n);
    if (n == 1)
    {
    return main();
    }
    else
    return 0;
}

Sample C++ program for calculating area of triangle and circle

Share this

Related Posts

There was an error in this gadget