+ 1
Can somebody tell me whats wrong in my code to find the area of triangle. It always show result as 0.
#include <iostream> using namespace std; int main () { int a , b; cout << "ENTER THE BASE OF TRIANGLE \n"; cin >> a; cout << "ENTER THE HIGHT OF TRIANGLE \n"; cin >> b; int sum = (1/2)*a * b; cout << sum; return 0; }
3 Respostas
+ 3
change (1/2) to (1.0/2) or (1/2.0)
because (1/2) is integer division so it will return 0.
+ 3
Use floats or doubles instead of int
- 1
float a, b, area;
area=(1/2) *a*b