August 27, 2012

C program to accept length of three sides of a triangle and find out the type of triangle

Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <stdio.h>
  2. #include <conio.h>
  3.  
  4. int main(){
  5.     int s1;
  6.     int s2;
  7.     int s3;
  8.     printf("Enter side 1: ");
  9.     scanf("%d", &s1);
  10.     printf("Enter side 2: ");
  11.     scanf("%d", &s2);
  12.     printf("Enter side 3: ");
  13.     scanf("%d", &s3);
  14.     printf("Triangle is ");
  15.     if(s1 == s2 && s1 == s3){
  16.         printf("Equilateral");
  17.     }else if(s1 == s2 || s2 == s3 || s1 == s3){
  18.         printf("Isoscles");
  19.         if(s1*s1 == s2*s2 + s3*s3 || s1*s1 == s2*s2 - s3*s3 || s1*s1 == - s2*s2 + s3*s3){
  20.             printf(" and is Right Angled");
  21.         }
  22.     }else{
  23.         printf("Scalene");
  24.         if(s1*s1 == s2*s2 + s3*s3 || s1*s1 == s2*s2 - s3*s3 || s1*s1 == - s2*s2 + s3*s3){
  25.             printf(" and is Right Angled");
  26.         }
  27.     }
  28.     printf(".");
  29.     getch();
  30.     return 0;
  31. }

No comments:

Post a Comment