p3

Write a C program to take three sides of a triangle as input and verify whether the triangle is an isosceles, scalene or an equilateral triangle.

/* 
 * Write a C program to check whether a Triangle is Equilateral,
 * Scalene or Isosceles 
 */  
  
#include <stdio.h>  
  
int main() {  
    int side1, side2, side3;   
    /* 
     * Take length of three sides of triangle as input 
     * from user using scanf 
     */  
    printf("Enter Length of Three Sides of a Triangle\n");  
    scanf("%d %d %d", &side1, &side2, &side3);   
  
    if((side1 == side2)&&(side2 == side3)) {
        /* All Sides Equal, Hence Equilateral */  
        printf("It is an Equilateral Triangle\n");  
    } else if (side1!=side2 && side2!=side3 && side3!=side1) {
        /* All sides different, Hence Scelene */  
        printf("It is a Scalene Triangle\n");  
    } else {
        /* Two sides equal, Hence Isoscales */ 
        printf("It is an Isoscales Triangle\n");  
    }  
  
    return 0;  
}

Output
Enter Length of Three Sides of a Triangle
10 10 10
It is an Equilateral Triangle
Enter Length of Three Sides of a Triangle
10 10 5
It is an Isoscales Triangle
Enter Length of Three Sides of a Triangle
7 10 5
It is an Isoscales Triangle

No comments:

Post a Comment