1,105,331 Community Members

To Check the Given Triangle is Isocles , Equilateral or Right Angled Triang

Member Avatar
(ashine80)
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

To Check the Given Triangle is Isocles , Equilateral or Right Angled Triang

#include<stdio.h>
    #include<ctype.h>
    #include<conio.h>
    #include<math.h>
    
    int main()
    {
      float Side1,Side2,Side3;
      float Flag1,Flag2,Sum_of_sq1,Sum_of_sq2,Sum_of_sq3;
      clrscr();
      printf("Enter Three Sides Side1 Side2 Side3 :");
      scanf("%f %f %f", &Side1 , &Side2 , &Side3);
      Flag1=(Side1==Side2)?(Side2==Side3?1:0):((Side2==Side3)?0:-1);
    	if(Flag1==0)
    	  { printf("Triangle is Isoceles\n");
    	    }
    	     if (Flag1==1)
    	      {  printf("Equilateral Triangle");
    		 }
    
    
    			  Sum_of_sq1=pow(Side1,2)+pow(Side2,2);
    			  Sum_of_sq2=pow(Side1,2)+pow(Side3,2);
    			  Sum_of_sq3=pow(Side2,2)+pow(Side3,2);
    			if (sqrt(Sum_of_sq1)==Side3 ||sqrt(Sum_of_sq2)==Side2 || sqrt(Sum_of_sq3)==Side1)
    			     printf("The Triangle is Right Angled Triangle");
    
    
    
    		 getch();
    		 return(0);
    
    }
Member Avatar
Nutster
Junior Poster
146 posts since Oct 2006
Reputation Points: 52 [?]
Q&As Helped to Solve: 23 [?]
Skill Endorsements: 3 [?]
 
0
 

Because of the way that pow and sqrt are written internally, it is usually much more efficient to multiply doubles rather than using these functions for squaring operations.

{
    Sum_of_sq1 = Side1*Side1 + Side2*Side2;
    Sum_of_sq2 = Side1*Side1 + Side3*Side3;
    Sum_of_sq3 = Side2*Side2 + Side3*Side3;
    if (Sum_of_sq1==Side3*Side3 || Sum_of_sq2==Side2*Side2 || Sum_of_sq3==Side1*Side1)
        printf("The triangle is a right triangle.\n");
}
You
Post:
Start New Discussion
Tags Related to this Article