Loops – Geometry – Problem #4
IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive
Problem Statement
Take input 3 numbers from the keyboard. Find out the number of digits of each of the three numbers. Hence find out whether you can construct a triangle whose three sides have length equal to the number of digits of the three numbers. Also if a triangle is possible, then comment on its type based on the length of its side, i.e whether it is a scalene, isosceles or equilateral triangle. You should display i) the number of digits of each of the three numbers that you have taken as input, ii) print ‘Yes’ if you can form a triangle with sides equal to the number of digits, ‘No’ otherwise and iii) display ‘Equilateral’, ‘Isosceles’ or ‘Scalene’ based on the nature of triangle, if you can form the triangle, else print ‘Triangle not possible’. To include more digits within a given number, you can assume ‘long int’ type data while taking input. You may further assume that the input numbers will always fall within the range of ‘long int’. Example 1: Input: 52 286325 74523 Output: 2 6 5 Yes Scalene [Reason: The first three outputs show the number of digits of the three input numbers. You can form a triangle with sides 2,6 and 5, which is a scalene triangle.] Example 2: Input: 1 23 7564 Output: 1 2 4 No Triangle not possible