Assignment 2
Assignment 2
---------------------------------------------------------------------------------------------------------------------
1) Write a C program that will take co-ordinates of three points A(x1, y1), B(x2, y2) and C(x3,
y3) from the user through keyboard. Assume that all the co-ordinates are integers. Check,
whether the three points are collinear or not. If they are not collinear, then name the triangle
they form (equilateral/isosceles/scalene/right-angle). (20M)
Example1:
Input:
A = (1 1)
B = (3 3)
C = (7 7)
The given points A, B, C are collinear.
Example2:
Input:
A = (1 2)
B = (3 4)
C = (5 6)
The given points A, B, C are not collinear.
They form isosceles rightangle triangle.
2) Read three real numbers, i.e., a, b, and c, which represent the coefficients of a quadratic
equation and display them in the exact form ax^2 + bx + c = 0. Hence check whether the
roots are real, coincident, or complex according to the rules of quadratic equation and
display it. No need to find out the roots separately. Additionally if the roots are complex,
determine the quadrant (i.e 1 st quadrant/2 nd quadrant/3 rd quadrant/4 th quadrant) of the
2D Argand plane in which the first complex root of the form a + ib lies. Note that complex
roots occur as conjugate pairs a+ib and a−ib, consider only the root in the form a+ib and
determine in which quadrant it lies. (20M)
Example1: (Please take the input and display the output as shown)
Input:
a:5
b:2
c:1
Output:
Equation: 5xˆ2 + 2x + 1 = 0
Roots: Complex
Quadrant of 1st complex root: 2nd [Reason: The first complex root is −0.2 + 0.4i as per
the given example, hence it lies in the 2nd quadrant]
Example2: (Please take the input and display the output as shown)
Input:
a:1
b:2
c:-3
Output:
Equation: xˆ2 + 2x − 3 = 0
Roots: Real
3) Take input from the keyboard the marks obtained by a student in Physics, English and
Sociology respectively and find out the highest among the three. Display the grade of the
student corresponding to the highest scoring subject, where grade = 'A' if the marks in the
highest subject >80%, grade = 'B' if the marks is between 60% to 80% and grade = 'C', if the
marks is less than 60%. Assume full marks to be 100. (Use Ternary operator to solve this
problem) (30M)
Example1:
Input:
Marks in Physics = 78
Marks in English = 92
Marks in Socialogy = 64
Output:
Grade in English = ‘A’
Example1:
Input:
Marks in Physics = 59
Marks in English = 52
Marks in Socialogy = 45
Output:
Grade in Sociology = ‘C’
4) Write a C program to display the salary of IITKGP’s employee based on his nature of job
(faculty, administrative staff and technical staff), designation and years of experience. The
inputs to be given to the program are Employee type, Designation, Basic and years of
experience. You may need to use switch statements (2-level) to solve this problem. Display
the input data as well as output in proper format. (30M)
Example:
Input:
Employ type = ‘a’
Designation = 2
Basic = 1,00,000
Experience = 5
Output:
Salary of Deputy Registrar = 1,20,000