Search This Blog

Thursday, October 13, 2011

For a valid triange,sum of any two sides must be grater than the third side. Write a program to read and evaluate its area if data are valid and exit with an appropriate message otherwise.Use two functions to check data and display area

   1:  #include<stdio.h>
   2:  #include<math.h>
   3:  #include<conio.h>
   4:  int dataok(float a,float b,float c)
   5:  {
   6:  if(a+b>c && b+c>a && c+a>b)
   7:  return(1);
   8:  else
   9:  return(0);
  10:  }
  11:  float getarea(float a,float b,float c)
  12:  {
  13:  float s,area;
  14:  s=(a+b+c)/2.0;
  15:  area=s*(s-a)*(s-b)*(s-c)/2.0;
  16:  area=sqrt(area);
  17:  return(area);
  18:  }
  19:  void main()
  20:  {
  21:  float a,b,c,area;
  22:  int valid;
  23:  printf("\nEnter a,b,c: ");
  24:  scanf("%f%f%f",&a,&b,&c);
  25:  valid=dataok(a,b,c);
  26:  if(valid==1)
  27:  {
  28:  area=getarea(a,b,c);
  29:  printf("\nArea of Triangel is: %f\n",area);
  30:  }
  31:  else
  32:  printf("The Sides do not form valid triangel\n");
  33:  getch();
  34:  }

No comments:

Post a Comment