Monday 2 July 2012

Check Valid Traingle in C

Code -


//_______Program will check whether the traingle is valid or not_______

/* A traingle is said to be valid if the sum of all the three angles of traingle is equal to 180 degree */

//_______Including Header Files___________

#include<stdio.h>

#include<conio.h>

//___________Inlcuded mainly for the getch() function____________

int main()
{
int first_angle = 0, second_angle = 0, third_angle = 0, sum = 0;

//_________Variable declaration and initialization__________

printf("\n\n\t\t____ Checking whether the traingle is valid or not _____");

/*____Prompting the user to enter th three angles of traingle and storing the user

input in  variables first_angle, second_angle, third_angle respectively____ */

printf("\n\n  Enter the First angle (in degrees)  - ");

scanf("%d", &first_angle);

printf("\n\n  Enter the Second angle (in degrees) - ");

scanf("%d", &second_angle);

printf("\n\n  Enter the Third angle (in degrees)  - ");

scanf("%d", &third_angle);


sum = first_angle + second_angle + third_angle ;

//_______Adding all the angles read through the user input_________

if (sum == 180)

//_______Checking for the triangle being valid_____________________

{
printf("\n\n\t\t\t _____ Traingle is valid ______");
}
else
{
printf("\n\n\t\t\t  _____ Traingle is invalid ______");
}

getch();

return 0;

/* ___return 0 tells the compiler that the program has executed successfully without

any error__ */

}

Follow Us on Facebook - Assignment Hub

No comments:

Post a Comment