Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
597 B
1
Indexable
Never
// calculate an area of triangle using the inline function
#include <iostream>
using namespace std;
// inline function, no need prototype
inline float triangle_area(float base, float height){
float area;
area = (0.5 * base * height);
return area;
}
int main(void)
{float b, h, a;
cout<<"Enter the value of b : ";
cin>>b;
cout<<"Enter the value of h : ";
cin>>h;
// compiler will substitute the inline function code here.
a = triangle_area(b, h);
cout<<"Area = (0.5*base*height)"<<endl;
cout<<"where, base = "<<b<<", height = "<<h<<endl;
cout<<"\nArea = "<<a<<endl;
return 0;
}