Monday, April 22, 2019

Moving Coins

  • Problem Description

    A triangle can be classified based on the lengths of its sides as equilateral, isosceles or scalene. 

    All 3 sides of an equilateral triangle have the same length. 

    An isosceles triangle has two sides that are the same length, and a third side that is a different length. 

    If all of the sides have different lengths then the triangle is scalene.

    Write a program that reads the lengths of 3 sides of a triangle from the user. Display a message indicating the type of the triangle.

  • Test Case 1

    Input (stdin)
    120

    60

    60

    Expected Output
    isosceles
  • Test Case 2

    Input (stdin)
    60

    60

    60

    Expected Output
    equilateral
Solution

#include <stdio.h>

int main()
{
    int side1, side2, side3;
    scanf("%d%d%d", &side1, &side2, &side3);

    if(side1==side2 && side2==side3) 
    {
        printf("equilateral");
    }
    else if(side1==side2 || side1==side3 || side2==side3) 
    {
        printf("isosceles");
    }
    else 
    {
        printf("scalene");
    }

    return 0;
}

No comments:

Post a Comment

Parity

Problem Description Ram and Sita playing the parity game. Two types of parity are there. One is odd parity and next is even parity. Ram will...