It is necessary to compile a program for calculating n Heron triangles where the lengths of the sides are consecutive integers and the area too, the problem with calculating the area of a triangle is this: I need to calculate an area for each triangle, that is, for example: I enter n triangles and on the output I want to get:
a=0 b=0 c=0 s=0 ...... a=3 b=4 c=5 s=6
and I have a, b, c as if accumulating values, and s, too, when entering 5 for example: a = 6 b = 12 c = 18 s = -2147483648
#include "pch.h" #include <iostream> #include <cmath> using namespace std; int n; int a,b,c,p= 0; int s = 0; int main() { cout << "Vvedite n:"; cin >> n; for (int i = 0; i <= n; i += 1, a += 1, b += 2, c += 3) p = (a + b + c) / 2; s = p * (p - a) * (p - b) * (p - c); s = sqrt(s); cout << "a=" << a << " b=" << b << " c=" << c << " s=" << s << endl; }
for
? - HolyBlackCatp == c
obtained, so that multiplication occurs by 0 in* (p - c)
. Maybe the formula for calculating the area is wrong? - HolyBlackCat