Thursday, April 30, 2015

C program on triangle


This page contains two programs related to triangle. The first program is to check whether a triangle is equilateral isosceles scalene and the second program checks whether a triangle is right angled or not.

1st Program  to check whether a triangle is equilateral isosceles scalene

#include  < stdio.h>
void main()
{
  int x,y,z;
  printf("\nEnter the sides of a triangle");
  scanf("%d %d %d",&x,&y,&z);
  if(x==y && y==z)
  {
  printf("\nThe triangle is equilateral");
  }
  else if(x==z || y==z || x==y)
  {
  printf("\nThe triangle is isosceles");
  }
  else
  {
  printf("\nThe triangle is scalene");
  }
getch();
}


C Program to check whether a triangle is right angled triangle


#include < stdio.h>
void main()
 {
     int a,b,c;    
     clrscr();
      printf("\nEnter the value of the sides:");
      scanf("%d%d%d",&a,&b,&c);
      if(a>b && a>c)
     {
        if(a*a==b*b+c*c)
        printf("It is a right-angled triangle");
        else
        printf("It is not a right-angled triangle");

      }
      if(b>c && b>a)
      {
      if(b*b==c*c+a*a)
      printf("It is a right-angled triangle");
      else
      printf("It is not a right-angled triangle");
      }
      if(c>a && c>b)
     {
      if(c*c==a*a+b*b)
      printf("It is a right-angled triangle");
      else
      printf("It is not a right-angled triangle");
      }
      getch();
}

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner