Logic:
A triangle is possible only if, sum of any two sides is greater than third side.
Algorithm
- Enter sides of triangle as a,b,c
- s = a+b;
- if(s>c)
- printf(“triangle is possible\n”);
- else
- printf(“triangle is not possible”);
Program
#include <stdio.h> int main() { printf("*************************************************************"); printf("\n*************************************************************"); printf("\n** WAP to enter 3 sides & check if a triangle is possible **"); printf("\n** Created by Sheetal Garg **"); printf("\n** Assistant Professor **"); printf("\n** Phone No:9467863365 **"); printf("\n*************************************************************"); printf("\n*************************************************************\n"); int a,b,c,s; printf("enter sides of triangle\n"); scanf("%d%d%d",&a,&b,&c); s = a+b; if(s>c) printf("triangle is possible\n"); else printf("triangle is not possible"); return 0; }
Output 1:
************************************************************* ************************************************************* ** WAP to enter 3 sides & check if a triangle is possible ** ** Created by Sheetal Garg ** ** Assistant Professor ** ** Phone No:9467863365 ** ************************************************************* ************************************************************* enter sides of triangle 3 4 5 triangle is possible
Output 2:
************************************************************* ************************************************************* ** WAP to enter 3 sides & check if a triangle is possible ** ** Created by Sheetal Garg ** ** Assistant Professor ** ** Phone No:9467863365 ** ************************************************************* ************************************************************* enter sides of triangle 3 4 7 triangle is not possible