Itp Assignment 2
Itp Assignment 2
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.
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
4. ALGORITHM ANALYSIS:
TIME COMPLEXITY GRAPH:
6. VERIFICATION OF THE CODE (OUTPUT): 9.REFERENCES:
• Let us C by yashvant kanetkar.
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.