Â
In this, we are going to see Functions, the program is based on function which Calculates, Profit or Loss.
The code given below can be used for TURBO C++ Compiler:-
#include<iostream.h>
#include<conio.h>
float calculate_area(float b, float h)
{
float area;
area = 0.5*b*h;
cout<<"The area of Triangle with base "<<b<<" and height "<<h<<" is = "<<area;
}
void main()
{
clrscr();
float base, height;
cout<<"\nEnter the Base and Height of the triangle\n";
cin>>base>>height;
calculate_area(base,height);
getch();
}
The code given below can be used for g++/gcc Compiler:-
#include<iostream>
using namespace std;
float calculate_area(float b, float h)
{
float area;
area = 0.5*b*h;
cout<<"The area of Triangle with base "<<b<<" and height "<<h<<" is = "<<area;
}
int main()
{
float base, height;
cout<<"\nEnter the Base and Height of the triangle\n";
cin>>base>>height;
calculate_area(base,height);
return 0;
}
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP