Computer Science, asked by Shajithjoseph, 1 year ago

Write C++ program to find the area of a triangle?

Answers

Answered by YashYatharth7
2
#include<iostream>
using namespace std;
void main( )
{
int base,height,area;
cout<<"Enter the base of traingle";
cin>>base;
cout<<"Enter the height of traingle";
cin>>height;
area=arOfTriangle(base,height);
cout<<"The area of triangle is "<<area;
}
public int arOfTriangle(int b,int h)
{
int ar=b*h*(1/2);
return ar;
}

Shajithjoseph: thankyou for this program.in my c++ compiler using namespace std wont work.. sorry it's my problem. i have not noticed that my compiler is turbo c++
siddhartharao77: In some of the turboc++ compilers namespace std doesn't work.
YashYatharth7: instead of namespace std, change the header file to iostream.h . This will work perfectly for turbo c++.
Shajithjoseph: Ok thanks . I will try.
Answered by siddhartharao77
5
#include<iostream.h>
int main()
{
double a,b,h;

cout<<"Enter base of triangle:";
cin>>b;

cout<<"Enter height of triangle:";
cin>>h;

a=0.5 * b * h;

cout<<"Area of the triangle is:" <<a;
return 0;
}

siddhartharao77: Thank You Shajith for the brainliest.
Shajithjoseph: ok
Similar questions