Task:

"Create a program that calculates the area of ​​a triangle, if a person has set the lengths of three sides A, B, C. Before calculating the area, check whether there is a triangle with given sides "

#include <math.h> #include <stdio.h> #pragma hdrstop //--------------------------------------------------------------------------- #pragma argsused int main(int argc, char* argv[]) { int a=12.0,b=7.0,c=8.0,p,s; if ((a>=(b+c))|(b>=(a+c))|(c>=(a+B))); else ("Impossible triagle"); p=(a+b+c)/2; s=pow(p*(pa)*(pB)*(pc),0.5); 

    2 answers 2

    And what does not work?

    With the exception of B instead of b (the compiler should be scolded for this) and the "Impossible triagle" message in elsewhere (db, on the contrary) is acceptable.

    Well, instead of pow() it's better to simply sqrt() .

    UPD

     double a=12.0,b=7.0,c=8.0,p,s; if ((a>=(b+c))|(b>=(a+c))|(c>=(a+b))) { printf("Impossible triagle\n"); } else { p=(a+b+c)/2; s=sqrt(p(pa)(pb)*(pc)); printf ("Triangle square is: %f\n",s); } 
    • one
      int a = 12.0, b = 7.0, c = 8.0, p, s; if ((a> = (b + c)) | (b> = (a + c)) | (c> = (a + b))) (p = (a + b + c)) / 2; s = sqrt (p * (pa) * (pb) * (pc)); else "Impossible triagle"; gives an error next to the "Impossible triagle" - smthelse
    • No, it’s necessary (hell, I didn’t immediately notice 1. lack of printf for "Impossible triagle" 2. double type int for variables) double a = 12.0, b = 7.0, c = 8.0, p, s; if ((a> = (b + c)) | (b> = (a + c)) | (c> = (a + b))) {printf ("Impossible triagle \\ n"); } else {p = (a + b + c) / 2; s = sqrt (p (pa) (pb) * (pc)); printf ("Triangle square is:% f \ n", s); } (This is already a hash code. Finally make a normal formatter ( or discard it at all ) for comments * I insert 4 spaces - no effect. - avp
    • one
      AVP, but I managed to check on DevC ++, as you, however, always promptly answered. Here you have another +1. And now it would be desirable for the guy to still check for non-negative and non-zero values ​​- at least. - Vyacheslav Kirichenko
    • one
      It is impossible to enter comments normally - it crawls off the edge of the screen (down), the handler shifts, and when you enter characters, it jumps backwards. Format the code fails. - avp
    • yeah, scrolling furious, no formatting - toxicdream
     #include <vcl.h> #include <math.h> #include <iostream> #include <string.h> #pragma hdrstop using namespace std; //--------------------------------------------------------------------------- #pragma argsused void rcout(char *string) //Для вывода в консоли кириллицы { char new_string[255]; CharToOem(string,new_string); cout<<new_string; } int main(int argc, char* argv[]) { double S,p,a,b,c; rcout("Введите а : "); cin>>a; rcout("Введите b: "); cin>>b; rcout("Введите c: "); cin>>c; p=(a+b+c)/2; S=sqrt(p*(pa)*(pb)*(pc)); cout<<"S = "<<S<<"\n"; system("pause"); return 0; } 
    • It is unlikely that for these classes use BCB. I remember from my memory, when studying C ++, the following requirement: to do work on MS Visual C ++, and there God knows :) - Vyacheslav Kirichenko
    • Only instead of system ("pouse"); it is better to make your own waiting for input (for example, via getch ()). And it even hurts to see how students are taught to mindlessly disperse the resources of the system. - avp