Program to tell the type of triangle based on its sides in C

Logic:

  • There are three types of triangle based on its sides
  • Equilateral Triangle: If all three sides are equal
  • Isosceles Triangle: If any two sides are equal
  • Scalene: If all sides are distinct

Algorithm

  1. Enter three sides as a,b,c
  2. if (a == b && b == c)
  3. printf(“Triangle is equilateral\n”);
  4. else if (a == b || b == c || a == c)
  5. printf(“Triangle is isosceles\n”);
  6. else
  7. printf(“Triangle is scalene\n”);

Program

#include <stdio.h>
int main()
{
    printf("*********************************************************");
    printf("\n*********************************************************");
    printf("\n** WAP to tell the type of triangle based on its sides **");
    printf("\n**        Created by Sheetal Garg                      **");
    printf("\n**          Assistant Professor                        **");
    printf("\n**          Phone No:9467863365                        **");
    printf("\n*********************************************************");
    printf("\n*********************************************************\n");
    int a, b, c;
    printf("Enter sides of triangle\n");
    scanf("%d%d%d", &a, &b, &c);
    if (a == b && b == c)
        printf("Triangle is equilateral\n");
    else if (a == b || b == c || a == c)
        printf("Triangle is isosceles\n");
    else
        printf("Triangle is scalene\n");
    return 0;
}

Output 1:

*********************************************************
*********************************************************
** WAP to tell the type of triangle based on its sides **
**        Created by Sheetal Garg                      **
**          Assistant Professor                        **
**          Phone No:9467863365                        **
*********************************************************
*********************************************************
Enter sides of triangle
4
4
4
Triangle is equilateral

Output 2:

*********************************************************
*********************************************************
** WAP to tell the type of triangle based on its sides **
**        Created by Sheetal Garg                      **
**          Assistant Professor                        **
**          Phone No:9467863365                        **
*********************************************************
*********************************************************
Enter sides of triangle
4
5
5
Triangle is isosceles

Output 3:

*********************************************************
*********************************************************
** WAP to tell the type of triangle based on its sides **
**        Created by Sheetal Garg                      **
**          Assistant Professor                        **
**          Phone No:9467863365                        **
*********************************************************
*********************************************************
Enter sides of triangle
3
4
5
Triangle is scalene
error: You can only copy the programs code and output from this website. You are not allowed to copy anything else.