You are on page 1of 9

CS19003:

Programming and
Data Structure Lab
Lab 6: Structures, 2D arrays

Sandip Chakraborty
Submission Requirements
 On top of your code, enter your name and roll numbers within
comments.
/***********************************
* Name: Your Name
* Roll: Your Roll
**********************************/
Programming Practices
 Do not copy the code from others. Any form of plagiarism will lead
to zero marks.
 Take help of the Internet to solve the problem.
 If you get a compilation error, try to read the error message and find
out the reason behind the error.
 If you do not get the expected output, try to debug your code with
extra printf statements.
Zero Tolerance to Plagiarism
 You are supposed to write the entire code yourself
 Do not copy the code / a block of code from any other sources (Internet, or
from your friends)
 We'll take a zero-tolerance policy against plagiarism – if a significant
portion of the code is similar between two students, both will be given
zero.
 We'll not entertain any alibi like "both of us have copied from the same
Internet source", "I had shared my Moodle password to my fried", etc.
Submission Instructions
 Once you are done with a code, save the code in your local machine
as A6.c.

 Upload A6.c in Moodle course page, corresponding to Assignment 6


-- https://moodlecse.iitkgp.ac.in/
Problem
 Define a C structure called Points. The structure has two floating
point variables – x and y, to denote the x-coordinate and y-coordinate
of the point in a 2D Euclidean space.

 Now assume that you have a set of 16 points in a 2D Euclidean


space. These points are represented in a 4x4 matrix.
Problem - Cont.
 Write a C program to find out the number of equilateral triangles that can be
formed using those 16 points.
 Specifically, you need to write the following three functions:
 GetInput (Point mat[][]) -- to populate the 2D matrix of 16 points
 Dist (Point a, Point b) -- distance between two points
 IsEquiTriangle(Point a, Point b, Point c) -- to check whether an equilateral
triangle be formed with the three points. Use the Dist(...) function to implement this
function.
 CountEquiTriangle(…) -- a recursive function to calculate the number of equilateral
triangles. Use the IsEquiTriangle(…) function to implement this function.
Problem – Cont.
 You can use additional arguments in the functions and define the
return type of the functions as appropriate.
 You should not use any global variable in your code. However, you
can use static variables if necessary.
 You should not use pointer variables in your code.
 You can use math.h library if needed
Marks Distribution
 GetInput (...) -- 3 Marks
 Dist (...) -- 4 Marks
 IsEquiTriangle (...) -- 5 Marks
 CountEquiTriangle (...) -- 6 Marks (Give 3 Marks if the function is
non-recursive)
 main() -- 2 Marks

You might also like