2. Write a program that reads three edges for a triangle and determines whether the input is valid. The input is valid if the sum of any two edges is greater than the third edge.
Sample Output:
Enter the first edge: 2
Enter the second edge: 2
Enter the third edge: 1
Can edges 2, 2, and 1 form a triangle? True
Can someone show me how this problem owuld look in C++ programming?
#include%26lt;iostream.h%26gt;
#include%26lt;conio.h%26gt;
main()
{
int a,b,c;
cout%26lt;%26lt; "Enter the first edge:";
cin%26gt;%26gt;a;
cout%26lt;%26lt; "Enter the second edge:";
cin%26gt;%26gt;b;
cout%26lt;%26lt; "Enter the third edge:";
cin%26gt;%26gt;c;
cout%26lt;%26lt;"Can edges"%26lt;%26lt;a%26lt;%26lt;","%26lt;%26lt;b%26lt;%26lt;", and"%26lt;%26lt;c%26lt;%26lt;"form a triangle?";
if((a+b==c)||(b+c==a)||(c+a==b))
cout%26lt;%26lt;"True";
else cout%26lt;%26lt;"False";
getch();
}
Reply:Yes. I think it can form a triangle. You can have one edge of length 2 on the left, other one on the right and the edge of 1 in the base. that can be a possibility
Reply:if you are talking about right angle triangle then let me know
Reply:I'm sure your instructor would like it better if you did it yourself. With that said, here's a little help:
1) Prompt for and read in the three values
2) Print "Can edges..." line without returning cursor
3) If all of these conditions are true, print true:
if (edge1+edge2 %26gt; edge3 %26amp;%26amp;
edge2+edge3 %26gt; edge1 %26amp;%26amp;
edge1+edge3 %26gt; edge2)
cout %26lt;%26lt; "true" %26lt;%26lt; endl;
else
cout %26lt;%26lt; "false" %26lt;%26lt; endl;
memory cards
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment