Você está na página 1de 2

TO CHECK WHETHER THE

USER VISITS HIS SECRET


FRIEND’S HOUSE OR NOT

ARPIT AGARWAL ANKIT GUPTA SAGAR BARMAN


IIT2019139 IIT2019138 IIT2019140
IIIT ALLAHABAD IIIT ALLAHABAD IIIT ALLAHABAD
Iit2019139@iiita.ac.in Iit2019138@iiita.ac.in Iit2019140@iiita.ac.in

KHUSHI GUPTA
IIT2019141
IIIT ALLAHABAD
Iit2019141@iiita.ac.in

ABSTRACT—In this paper we have devised an Only if the friend is at home and both the conditions
algorithm to insert friend’s information using are met then only, he will be able to meet them.
structure in C. In order to meet his secret friend, Another condition imposed is that if more than 3
the user calls every friend to check whether they
are at home or not. Also, few other conditions friends satisfy the above conditions then he will stay
have to be checked before visiting. at home.
KEYWORDS—struct, char, bool, dist. Example: Input: (n=4), count=0
Co-ordinates of the user (0,0)
I. INTRODUCTION
Friend 1 (2,3): Name= abc, Bool=TRUE, Ph
STRUCTURE: A struct in a C programming Number=34567
language is a composite datatype declaration that
defines a physically grouped list of variables under a Friend 2 (3,4): Name= def, Bool=TRUE, Ph
block of memory, allowing the different variables to Number=34567
be assessed by the struct declared variable.
Friend 3 (5,3): Name= ghi, Bool=TRUE, Ph
In this paper we have created a structure named Number=34567
“friend” which includes the information like name of
the friend, coordinates of the friend (x, y), Boolean Friend 4 (4,3): Name= jkl, Bool=FALSE, Ph
variable (TRUE if friend is at home & FALSE if Number=34567
friend is NOT at home) and a 5-digit phone number.
Using for loop, the program takes the information of Now our program will check whether the friends are
friends in an array of structure datatype and then at home or not. For friend 1, since he is at home
checks whether the user is able to meet his secret (bool=true) and the distance from the user is less than
friend or not. 10 units, therefore the count will increase by 1. The
same would happen for friend 2 and friend 3. But for
II. ALGORITHM friend 4, since the bool is false therefore the count
DESCRIPTION will not increase by 1. The user will go and visit his
We start by asking the user his co-ordinates and friend as the conditions are met for 3 friends and
then how many friends he wants to contact(n). By count is less than or equal to 3.
using array of structure, we take the input of all the
information of the friends including name of the
friend, coordinates of the friend (x, y), boolean
variable and a 5-digit phone number.
We then use a for loop to calculate the distance
between the friends’ house and the user. We check
whether the friend is at home or not and also if he
lives at a distance less than 10 units from the user.
III. PSEUDO CODE

start
declare dist,n,i,b,k,l,count as integers
declare struct friend as globally data type
struct friend

{
char name[];
int x,y;
bool var;
char no[];
} a[]; IV.TIME COMPLEXITY
read k,l as user coordinates
read n SNo. N Time (sec)
for(i=0 to i<n) 1 2
Coordinate= (2,3) 0.101129
read a[i].name, a[i].x,a[i].y,a[i].no,b
a[i].var=b Coordinate= (3,4)
end for 2 3
for(i=0 to i<n) Coordinate= (2,5)
0.102227
find dist (square of the distance between user and Coordinate= (5,7)
friend) Coordinate= (7,3)
assign dist 3 4
if a[i].var is true & dist<100 Coordinate= (4,4)
count increment by 1 Coordinate= (4,7) 0.104664
end for Coordinate= (3,9)
if count>3 Coordinate= (7,10)
print "NO"
else
print "YES"

V.CONCLUSION VI.REFERENCES

From this paper we can conclude that the algorithm is [1] Beginning C – By Ivon Horton
an Ω(1)-O(n) algorithm. [2] Structures in C
The algorithm takes minimum time when n is least https://www.geeksforgeeks.org/structures-c/
and coordinates are small. This is because the
iterations will be less when n is less.

Você também pode gostar