Introduction

The main purpose of this blog is to share our experience with the world and get experience from the world. This will be a new venture for us and we are sure, we shall learn a lot with it. we will try to Explore our mind which will be very helpful for all us. As from its name, its a blog covering all the topics. we will try to post all the interesting topics and give our opinion. Do give your point of view in comments.


"NAVIGATE VIA BLOG ARCHIVE ON RIGHT TO GET WHAT YOU ARE LOOKING FOR"


Thursday, January 27, 2011

C CODE FOR TRIANGLE AREA AND ITS TYPE

In the following code i have included the math library as well because the use of square root function was required . There are plenty others functions located in the math library .Dont forget to write –lm while compiling as it is required for math library if ur working on linux environment eg gcc test.c –lm . Anyways here is the code as the topic says

 

#include<stdio.h>
#include<math.h>
int main ()
{
float a,b,c,s,area;
printf("\nENTER THE THREE SIDES OF TRIANGLE\n");
scanf("%f%f%f",&a,&b,&c);
if( ((a+b)>c) && ((a+c)>b) && ((b+c)>a))
  {
     if ((a==b) && (a==c))
    {printf("\nEQUILATERAL TRIANGLE\n");}
     else
       {
     if((a==b) || (a==c) || (b==c) )
       printf("\nISOCELES TRIANGLE\n");
     else
       printf("\nSCALENE TRIANLGE\n");
    }
    s=(a+b+c)/2;
    area=sqrt(s*(s-a)*(s-b)*(s-c));
    printf("AREA IS %.2f sq units\n",area);
    }
else
{printf("TRIANGLE NOT POSSIBLE");}
retur

No comments:

Post a Comment

Related Posts with Thumbnails