0

Write a C++ program to check whether a triangle is valid or not, your program should have the following function:

checktriangle(int,int,int)

This function takes the three integer type variables as the angle of three sides. And perform the validity check for the triangle as follows:

A triangle is valid if the sum of all the three angles is equal to 180 degrees.
After performing the validity check function should display the appropriate message i.e. either triangle is valid or not valid.

Sample Output:

Enter the first angle
45
Enter the second angle
45
Enter the third angle
90
valid triangle
Press any key to continue…

3
Contributors
5
Replies
17
Views
3 Years
Discussion Span
Last Post by sohail.butt.144
0
#include<stdio.h>
#include<conio.h>
  main()
{
  int x,y,z,sum=0;
  clrscr();
  printf("\n enter the angles x,y and z");
  scanf("\n %d%d%d",&x,&y,&z);
  checktriangle(x,y,z);
}

 Void checktriangle(int i,int j,int k)
 {

  sum=i+j+k;
  if(sum==180)
{
  printf("\n triangle is valid ");
}
  else
{
  printf("\n triangle is not valid");
}
  return (0);
}
0

On the downside, that won't compile, and even when the capitalisation of Void is fixed, it still won't compile on any compiler from this side of the mid-nineties. Still ,enough for you to work out a C++ version for yourself.

Edited by Moschops

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.