Initial Basics – Geometry – Problem #7

IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive

Difficulty: hard

Problem Statement

Write a C program to perform the following tasks. 1. Let P = (x1, y1) and Q = (x2, y2) be two points in the two-dimensional plane. Assume that the straight line join P and Q does not pass through the origin. These coordinates should be floatingpoint numbers. 2. Print the equation of the straight line joining P and Q in aX + bY + c = 0 format. You are not required to ensure that the gcd of a, b, and c is 1. Any valid equation is acceptable. 3. Print the distance of the straight line from the origin. 4. Print the mirror-image of the origin with respect to the straight line joining P and Q. 5. Take R = (x3, y3) a point as input from the user. Print if R lies on the straight-line joining P and Q. 6. Print the mirror-image of R with respect to the straight line joining P and Q. You may require math library functions. For that, you use the following code in the beginning of your code. #include<math.h> To compile your code, you the following command in terminal. gcc ./program.c -lm To compare a floating point variable, say x, with a floating point constant, say 2, use the following code ``if (x== 2.0f)'' or ``if (x > 2.0f)'' etc. Sample Output: palash@palash-ThinkPad-X1-Yoga-3rd:~$ ./a.out ./a.out Write x1: 3.4 Write y1: -2.6 Write x2: -5.2 Write y2: -19 Equation of the line joinig the two points is 16.400000X+(-8.600000)Y+(-78.120003)=0 The distance of the line from the origin is 4.218576 Mirror image of the origin with respect to the line is (7.472110,-3.918302) Write x3: 32 Write y3: -9.2 The point (32.000000,-9.200000) does not lie on the straight line Mirror image of (32.000000,-9.200000) with respect to the line is (-18.292313,17.172802) palash@palash-ThinkPad-X1-Yoga-3rd:~$

Back to Lab Problems
Initial Basics/Geometry/Problem #7

Lab Problem Statement

Specifications & Problem DetailsIIT Kharagpur PDS Archive
Loading question...

Interactive C Compiler · Problem #7

WASM In-Browser

Runs directly on your machine · Zero remote server dependency

Compiler downloads on first Run (large, saved in your browser after that)
main.cCtrl + Enter to run
1
2
3
4
5
6
7
Input (stdin)given to scanf / cin
Output

Output appears here. Press Run to compile and execute.