-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.c
93 lines (77 loc) · 1.7 KB
/
game.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>
float distance (int ptz[], int pt[],int j){
float d ;
int i;
float ptd[100];
float sum = 0;
for ( i = 0; i < j; i++)
{
if (ptz[i] - pt[i] > 0)
{
ptd[i] = ptz[i] - pt[i];
}else
{
ptd[i] = pt[i] - ptz[i];
}
sum = sum + (ptd[i] * ptd[i]);
}
d = sqrt(sum);
return d;
}
int main(){
float dist ;
int pt[100];
int i = 0;
int j = 2;
int z = 1;
int k = 0;
int ptz[100];
int m = 1;
p1 :
srand(time(0));
for ( k = 0; k < j; k++)
{
ptz[k] = rand() % 100;
}
// int x = rand() % 100 ;
// int y = rand() % 100 ;
while (z)
{
printf("enter %dd coordinates with max value of each be less than 100 and greater than 0 ;",j);
// scanf("%d %d",pt[i],pt[i+1]);
for ( k = 0; k < j; k++)
{
scanf("%d",&pt[k]);
}
for ( k = 0; k< j; k++)
{
if (ptz[k] == pt[k])
{
m = 1;
}else
{
m = 0;
}
}
if(m){
printf("you are pretty clever , but you will not out wit me next time\n");
printf("to try next level press 1 , to exit press 0;");
scanf("%d",&z);
if (z == 1)
{
j++;
goto p1;
}else
{
break;
}
}else
{
dist = distance(ptz,pt,j);
printf("you are %f units away from target; \n",dist);
}
}
}