AceTheInterview
Jobs in Pune | Work better in teams | Socialize with friends | Submit Q&A | Tell a friend
Search site for 

Top 100 Interview Questions & Answers in a convenient and easy to read book!

“I bought this guide a few days ago to prepare for my interview with Oracle. Many of the questions they asked me were from this guide. I found this book absolutely great!”

– Ravi, California

Read more comments...

Interview Questions And Answers RSS Feed

Answers »

  1. Submitted By: MS — January 30, 2008
    -4 votes
      + -

    Keep a count such that count = 2 if two values are the same, and count=3 if all the same.

    then count=3 implies equi
    =2 - isos
    =1 - scalene

  2. Submitted By: nilesh — January 30, 2008
    +1 votes
      + -

    def ValidateTraingle(side1, side2, side3)
    triangleSides = [side1, side2, side3]
    triangleSides = triangleSides.sort
    if (triangleSides[2] >= triangleSides[0] + triangleSides[1]) then
    # Error in the traingle dimensions
    return 4
    elsif (triangleSides[0] == triangleSides[1]) and (triangleSides[1] == triangleSides[2]) then
    # Equilateral traingle
    return 3
    elsif (triangleSides[0] == triangleSides[1]) or (triangleSides[1] == triangleSides[2]) or (triangleSides[0] == triangleSides[2]) then
    # Isosceles traingle
    return 2
    elsif (triangleSides[0] != triangleSides[1]) and (triangleSides[1] != triangleSides[2]) then
    # Scalene traingle
    return 1
    end

    end

  3. Submitted By: Arun — February 2, 2008
    +16 votes
      + -

    int isTriangle (int x1, int x2, int x3) {

    if ((x1 >= x2 + x3) || (x2 >= x1 + x3)
    || (x3 >= x1 + x2)) {
    return 0; // no triangle possible
    }

    if (x1 == x2 == x3) return 1; // Equilateral

    if (x1 == x2 || x2 == x3
    || x1 == x3) {
    return 2; // Isoceles
    }

    return 3; //Scalene
    }

  4. Submitted By: Cylus — February 3, 2008
    +3 votes
      + -

    1) The three integers are a, b and c
    2) If not (a+b > c and a+c > b and b+c > a) then input is not valid
    3) if a= b =c then return equilateral
    4) If ( a= b or a=c or b=c) then return isosceles
    5) Arrange variables such that a > b > c and
    if sqr(a) = srq(b) + sqr(c) then return right angle triangle
    6) Else scalene triangle

  5. Submitted By: Indian_analyst — February 21, 2008
    -7 votes
      + -

    enum RectangleType { Scalene, Isosceles, Equilqteral, NotARectangle};
    template
    struct RectComaparator {
    RectComparator(){}
    bool compare(const T&lhs, const T& rhs) {
    return (lhs > rhs);
    }
    };
    RectangleType
    template
    detectRectangleType (cosnt T& a, const T& b, const T& c) throws std::runtime_error {
    //validate in parameters
    if (!a || !b || !c) {
    //throw exception
    }
    //store and sort in array
    T store[3]= {a, b, c};
    RectComparator comp;
    std::sort(store, comp); //in desc order
    //store[0] has the greatest value
    if (store[0] > store[1] + store [2]) {
    return NotARectangle;
    }
    if ((store[0] == store[1] == store[2])
    return Equilateral;
    else if (store[0] == store[1] || store[1] == store[2]) return Isosceles;
    else
    return Scalene;
    }
    }
    alternatively, store the values in a set
    Set stores unique sorted values, so if the size of the set is 1 then it is equilateral etc…

  6. Submitted By: Manisha — February 26, 2008
    -3 votes
      + -

    I’m basically a php programmer, not much conversant with the microsoft’s scripting technologies/syntaxes. Just gave a try on the logic. Here it follows :

    —- —- —- —- —- —- —- —- —-
    function typeOfTriangle($x, $y, $z){

    $a=array($x,$y,$z);
    sort($a);

    echo “
    Type of triangle that can be drawn with sides with respective lengths as $x, $y, $z : “.($a[2]
    “;

    }

    typeOfTriangle(11,10,17);
    typeOfTriangle(11,10,11);
    typeOfTriangle(11,11,11);
    typeOfTriangle(11,110,11);
    typeOfTriangle(11,0,11);
    —- —- —- —- —- —- —- —- —-
    //output :

    Type of triangle that can be drawn with sides with respective lengths as 11, 10, 17 : Scalene

    Type of triangle that can be drawn with sides with respective lengths as 11, 10, 11 : Isosceles

    Type of triangle that can be drawn with sides with respective lengths as 11, 11, 11 : Equilqteral

    Type of triangle that can be drawn with sides with respective lengths as 11, 110, 11 : None

    Type of triangle that can be drawn with sides with respective lengths as 11, 0, 11 : None

    —- —- —- —- —- —- —- —- —-
    [Note : Here assuming following factors : sides’ lengths are numbers (signed/unsigned int/floats) and type of triangle is to be decided on sides and not on angles, in the resultant triangle. ]

    regards,

    - Manisha

  7. Submitted By: krokodilov — February 26, 2008
    -2 votes
      + -

    enum TRIANGLE_TYPES
    {
    TT_NONE = 0×00,
    TT_CONFLUENT = 0×01,
    TT_COMMON = 0×02,
    TT_EQUILATERAL = 0×04,
    TT_ISOSCELES = 0×08,
    TT_RECTANGULAR = 0×10,
    TT_CONFLUENT_ISOSCELES = TT_CONFLUENT | TT_ISOSCELES,
    TT_RECTANGULAR_EQUILATERAL = TT_RECTANGULAR | TT_EQUILATERAL,
    TT_RECTANGULAR_ISOSCELES = TT_RECTANGULAR | TT_ISOSCELES
    };

    TRIANGLE_TYPES triangle_kind(int a, int b, int c)
    {
    TRIANGLE_TYPES type = TT_NONE;

    if ( a

  8. Submitted By: Venkat — February 26, 2008
    +1 votes
      + -

    Validate(sides[3])
    {
    sides.sort; //asc order
    if(sides[2] > side[0] + side[1])
    {
    return 0;
    }
    else
    {
    if(side[0] == side [2])
    {
    return equi;
    }
    elseif(side[0] == side[1])
    {
    return isoc;
    }
    return scalene;
    }
    }

  9. Submitted By: Manisha Bhosale — February 28, 2008
    +2 votes
      + -

    Core logic follws here :

    1. A triangle can be drawn only if length of the Longest side is less than the sum of other two sides.
    otherwise => None

    2. If all the side lengths are distinct => Scalene
    3. If only two of them are of equal length => Isosceles
    3. If all of them are of same length => Equilqteral

    regards,

    - Manisha

  10. Submitted By: Manoj Ghosh — March 23, 2008
    -1 votes
      + -

    int arr[3];
    sort(arr);

    if (arr[0]+arr[1]

  11. Submitted By: Satyajeet — March 24, 2008
    not yet rated
      + -

    I think you should also check for negative inputs.
    For example all the functions suggested above will decide on equilateral triangel for an input -1,-1,-1.

    The unsigned one will work fine because you have masked the input itself but for complete functionality one should check for negative numbers.

  12. Submitted By: Panduranga chary — May 5, 2008
    not yet rated
      + -

    We could give the arguments sizes in such a way which satisfy the a+b >= c, but without angle how can we say it forms a triangle.

  13. Submitted By: dtc — June 12, 2008
    not yet rated
      + -

    panduranga: the way you pose it is ambiquous.

    For sure we can say this:

    suppose we name the three sides lengths such that:
    a

  14. Leave an Answer/Comment

    To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
    Click to hear an audio file of the anti-spam word

Our Sponsors
Our Sponsors
Contact Us | FAQ | Sitemap | Terms of Use | Privacy Policy | Tell a Friend

Copyright © 1999-2006 Jeeve Technologies LLC. All rights reserved.