Functions and Recursions – Geometry – Problem #3

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

Difficulty: hard

Problem Statement

A polygon is said to be simple if its non-adjacent sides do not intersect each other. Write a C program to find out whether an input polygon is simple. It should have the following input/output behavior:  The program first takes in the number of vertices from the user.  Then it takes in n integer points (i.e., points with integer coordinates) as vertices from the user. The user is assumed to enter these points either in clockwise or in anticlockwise order. In other words, the sides of the polygon connect consecutive vertices in the input sequence (and the last and the first vertices).  The program outputs whether or not the polygon is simple. If the polygon is not simple, it also outputs the number of intersection points among the non-adjacent sides.  You should write a function that takes as input the endpoints of two straight line segments and returns whether they intersect or not. Call this function from main() to determine the intersection between every two non-adjacent sides of the polygon.

Back to Lab Problems
Functions and Recursions/Geometry/Problem #3

Lab Problem Statement

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

Interactive C Compiler · Problem #3

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.