Wednesday, March 14, 2012

Side of a Triangle

Reads three nonzero float values and determines and prints if they could represent the side of a triangle.
/*
   title: SidesOfATriangle
   coder: aeriqusyairi
   date: dec30 2011
   
   Note: Use triangle Inequality Theorem - 
      The longest side of any triangle must
      be less than the sum of the two
      shorter sides
*/
#include<stdio.h>
#include<stdlib.h>

int main(){
   float a=0,b=0,c=0,swap=0;
   printf("Input 3 nonzero values:\nFirst\n-");
   scanf("%f", &a);
   printf("Second\n-");
   scanf("%f", &b);
   printf("Third\n-");
   scanf("%f", &c);
   
   if(a > b && a > c){
      swap = c;
      c = a;
      a = swap;        
   }else if(b > a && b > c){
      swap = c;
      c = b;
      b = swap;       
   }
   
   printf("%s\n", c < a + b ? "Possible side of triangle.\n" : "Impossible side of a triangle.\n" );
   system("pause");
   return 0;
}

No comments:

Post a Comment