C Language Computing Triangle area code _c language

Source: Internet
Author: User
Tags abs

Copy Code code as follows:

Area Formula S = (A+B+C)/2 areas = sqrt (S * (s-a) * (s-b) * (s-c));
Small job to find the area of the triangle

int check (double a);
int Check2 (double A, double b, double c);

#include <stdio.h>
#include <math.h>
int main (void)
{
Double area = 0;
Double S;
Double a,b,c;
printf ("Enter the length of the three sides of the triangle (a b C):");
scanf ("%lf%lf%lf", &a, &b, &c);
if (check (a) = = 1 && check (b) = = 1 && check (c) ==1)
{
if (Check2 (a,b,c) = = 0)
{
printf ("You are not entering a triangle. Please re-enter \n\r");
return 0;
}
else if (Check2 (a,b,c) = = 1)
{
s = (a+b+c)/2;
Area = sqrt (S * (s-a) * (s-b) * (s-c));
printf ("The size of the triangle is:%g\n\r", area);
}
}
Else
printf ("Input is incorrect, please re-enter. \n\r");
return 0;
}

Determine if the data entered is valid
int check (double a)
{
if (a > 0)
return 1;
Else
return 0;
}

Determine if the triangle is valid

int Check2 (double A, double b, double c)
{
if (((a+b) <=c) | ((a+c) <=b) | ((c+b) <=a))
return 0;
if (ABS (a-b) >=c | ABS (A-C) >=a | ABS (C-B) >=a)
return 0;
Else
return 1;
}

Think, area is not a garbage value ah. So don't write so many lines declaring variables eh ....

Modified a number of

Copy Code code as follows:

Area Formula S = (A+B+C)/2 areas = sqrt (S * (s-a) * (s-b) * (s-c));
Small job to find the area of the triangle

int check (double a);
int Check2 (double A, double b, double c);

#include <stdio.h>
#include <math.h>
int main (void)
{
Double area,s,a,b,c;
printf ("Enter the length of the three sides of the triangle (a b C):");
scanf ("%lf%lf%lf", &a, &b, &c);
if (check (a) = = 1 && check (b) = = 1 && check (c) ==1)
{
if (Check2 (a,b,c) = = 0)
{
printf ("You are not entering a triangle. Please re-enter \n\r");
return 0;
}
else if (Check2 (a,b,c) = = 1)
{
s = (a+b+c)/2;
Area = sqrt (S * (s-a) * (s-b) * (s-c));
printf ("The size of the triangle is:%g\n\r", area);
}
}
Else
printf ("Input is incorrect, please re-enter. \n\r");
return 0;
}

Determine if the data entered is valid
int check (double a)
{
if (a > 0)
return 1;
Else
return 0;
}

Determine if the triangle is valid

int Check2 (double A, double b, double c)
{
if (((a+b) <=c) | ((a+c) <=b) | ((c+b) <=a))
return 0;
if (ABS (a-b) >=c | ABS (A-C) >=a | ABS (C-B) >=a)
return 0;
Else
return 1;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.