0% found this document useful (0 votes)
34 views3 pages

Itp Assignment 2

The document discusses calculating the Manhattan and Euclidean distances between pairs of points. It defines a point structure with x and y integer values, declares arrays of points, defines functions to calculate the distances and prints the results.

Uploaded by

G Venkatesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views3 pages

Itp Assignment 2

The document discusses calculating the Manhattan and Euclidean distances between pairs of points. It defines a point structure with x and y integer values, declares arrays of points, defines functions to calculate the distances and prints the results.

Uploaded by

G Venkatesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

QUESTION:
Define a structure named point with the 3) For finding the Manhattan distance and
following two members: Euclidian distance we create functions named
mdist and edist respectively which takes
A) An integer value x. structure arrays and number of coordinates(n)
B) An integer value y and write a modular as input.
code (each task in a separate function) to
perform the following task: 4) We have included header file<math.h> to
use functions fabs() for taking modulus of
a) To Declare two arrays of size 10 each. difference of coordinates in function mdist
b) To Find pairwise Euclidean distance and and pow() for taking square and root of
Manhattan distance (member at index 0 in coordinates in function edist.
first array with member at index 0 in second
 Manhattan distance=|x1-x2|+|y1-y2|
array and so on).
and
2. INTRODUCTION:  Euclidian distance= {(x1-x2)2+(y1-y2)2}1/2

Structures are user defined data types which 5) Also, we have used for loop in functions
are used when we want to store dissimilar mdist and edist to iterate the operations and
data together. Structure elements are always print the distances till the number of
stored in contiguous memory locations. coordinates entered by the user.

The general form of a structure is as follows: 6) In functions we have used P1[i].x -P2[i].x
and P1[i].y – P2[i].y that is member at index i
Struct< structure name> { in first array is operated with member at
structure element 1; index i in second array and so on.

structure element 2; The above algorithm will become clearer with


the following example:
};
1)Suppose we want to find distances for 2
Here we found Manhattan and Euclidian pairs of coordinates that are (1,2) (3,4) (5,6)
distance which are as follows: (7,8).
 Manhattan distance=|x1-x2|+|y1-y2| 2) Struct point P1[0] = (1,2)
and
Struct point P1[1] = (3,4)
 Euclidian distance= {(x1-x2)2+(y1-y2)2}1/2
Struct point P2[0] = (5,6)
3. ALGORITHM DESIGN:
Struct point P2[1] = (7,8)
1) First, we make a structure named point to
store two integers x and y and define two 3)After taking inputs these values will be
structure arrays each of size 10 namely struct copied to functions mdist and edist.
point P1[10] and struct point P2[10].
4)In function mdist the following operations
2) Now we ask the user to enter the number will take place:
of points he wants to find the distances for
and use a for loop to take inputs of |P1[0].x- P2[0].x|+|P1[0].y – P2[0].y|;
coordinates from the user for each structure |P1[1].x- P2[1].x|+|P1[1].y – P2[1].y|
array.
5)In function edist the following operations 5.CODE FOR THE QUESTION:
will take place:

a=(p1[0].x-p2[0].x) 2;

b=(p1[0].y-p2[0].y) 2;

c=(a+b)1/2

And

a=(p1[1].x-p2[1].x) 2

b=(p1[1].y-p2[1].y) 2

c=(a+b)1/2

clearly, calculations are happening such that


the member at index 0 in first array is
operated with member at index 0 in second
array and similarly the member at index 1 in
first array is operated with member at index 1
in second array.

6) Finally, the corresponding distances are


printed with the help of printf function.

4. ALGORITHM ANALYSIS:
TIME COMPLEXITY GRAPH:
6. VERIFICATION OF THE CODE (OUTPUT): 9.REFERENCES:
• Let us C by yashvant kanetkar.

• Geeks for Geeks.

7.CONCLUSION:
From this report we conclude that we can
write structures to store any data type
and also create structure arrays and use
functions to draw and use any kind of
information from the data stored in
Structures.
8. ACKNOWLEDGEMENT:
We would like to thank Dr.Mohammad Javed
sir and our mentor Tejasvee mam for guiding
us to complete this report.

You might also like