Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
0
of 0 vote

Is it a school homework?

Triangles can be classified according to the relative lengths of their sides:

* In an equilateral triangle, all sides are of equal length. An equilateral triangle is also an equiangular polygon, i.e. all its internal angles are equal—namely, 60°; it is a regular polygon.[1]
* In an isosceles triangle, two sides are of equal length (originally and conventionally limited to exactly two).[2] An isosceles triangle also has two equal angles: the angles opposite the two equal sides.
* In a scalene triangle, all sides have different lengths. The internal angles in a scalene triangle are all different.[3]

Image removed by sender. Equilateral Triangle


Image removed by sender. Isosceles triangle


Image removed by sender. Scalene triangle

Equilateral


Isosceles


Scalene

Triangles can also be classified according to their internal angles, described below using degrees of arc:

* A right triangle (or right-angled triangle, formerly called a rectangled triangle) has one 90° internal angle (a right angle). The side opposite to the right angle is the hypotenuse; it is the longest side in the right triangle. The other two sides are the legs or catheti (singular: cathetus) of the triangle.
* An oblique triangle has no internal angle equal to 90°.
* An obtuse triangle is an oblique triangle with one internal angle larger than 90° (an obtuse angle).
* An acute triangle is an oblique triangle with internal angles all smaller than 90° (three acute angles). An equilateral triangle is an acute triangle, but not all acute triangles are equilateral triangles.

Image removed by sender. Right triangle


Image removed by sender. Obtuse triangle


Image removed by sender. Acute triangle

Right


Obtuse


Acute




Image removed by sender. \underbrace{\qquad \qquad \qquad \qquad \qquad \qquad}_{}


We can find CosA, CosB , CosC using the cosine formula.

Image removed by sender. \cos C=\frac{a^2+b^2-c^2}{2ab}\,.

If ( a+b <= c || b+c <=a || c+a <= b)
Print Triangle cannot be formed.
cosA = <apply formula>
cosB = <apply formula>
cosC = <apply formula>

Print a==b ? (b==c ? "Equilateral":"Isosceles") : (b==c?"Isosceles" : "Scalene";

If ( 0 == CosA || 0 == CosB || 0 == CosC)
Print Right Angled
else If ( 0 != CosA && 0 != CosB && 0 != CosC)
Print Oblique Angled
else If ( 0 > CosA || 0 > CosB || 0 > CosC)
Print Obtuse Angled
else If ( 0 < CosA && 0 < CosB && 0 < CosC)
Print Acute Angle
else
Print "Triangle cannot be formed."

- Ankush Bindlish December 12, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Better way is to try to find the area of the triangle using Hero's formula. Let a,b,c be the three sides of the triangle.

s = (a+b+c)/2;
if(s*(s-a)*(s-b)*(s-c) <= 0){
  "Error"
}
else if((a==b)||(b==c)||(c==a)){
 "Isoceles"
}
else if(a==b && b==c){
  "equilateral"
}
else if((a != b) && (b != c) && (c != a)){  //or just else, no need of comparison
  "Scalene"
}

- neeraj December 15, 2009 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More