This blog consists of C and C++ programs. C and C++ programming is the basics to learn any programming language. Most of the programs are provided with their respective outputs. This blog also contains Data Structures programs using Object-Oriented Programming (C++). Some of the best books for learning C and C++ programming are also mentioned.

Showing posts with label Triangle. Show all posts
Showing posts with label Triangle. Show all posts

Tuesday, 30 July 2013

Program to find the type of Triangle

#include<stdio.h>
#include<math.h>
int main()
{
int a, b, c;
clrscr();
printf("Enter the values of the sides of the triangle: \n");
scanf("%d %d %d", &a, &b, &c);
if ((a + b > c && a + c > b && b + c > a) && (a > 0 && b > 0 && c > 0))
{
if (a == b && b == c)
{
printf("Equilateral Triangle");
}
else if (a == b || b == c || a == c)
{
printf("Isosceles Triangle");
}
else
{
printf("Scalene Triangle");
}
}
else
{
printf("Triangle formation is not possible");
}
getch();
}


Friday, 21 June 2013

Program to find the area of a Triangle

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c;
float s,d,area;
clrscr();
printf("Enter the length of the three sides");
scanf("%d%d%d",&a,&b,&c);
s=(a+b+c)/2;
d=(s*(s-a)*(s-b)*(s-c));
area=sqrt(d);
printf("Area of the triangle = %f sq units", area);
getch();
}