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
- Enter three sides as 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”);
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