Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
chazog
/
iax0583
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
67c703f9
authored
Dec 16, 2018
by
chazog
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
781257d9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
93 additions
and
0 deletions
Lab10/Task2.c
Lab10/Task2.c
0 → 100644
View file @
67c703f9
#include <stdio.h>
void
AskInput
(
int
N
,
double
distance
[
N
],
double
speed
[
N
]);
void
PrintInput
(
int
N
,
double
input
[
N
]);
double
FinDist
(
double
distance
,
double
speed
,
double
time
);
int
FinCounter
(
int
N
,
double
fdistance
[
N
]);
int
main
()
{
int
N
,
i
,
Nailed
;
double
t
;
printf
(
"Enter the amount of objects(not more than 15):
\n
"
);
do
{
scanf
(
"%d"
,
&
N
);
if
(
N
>
15
)
{
printf
(
"LMAO! try again:
\n
"
);
}
}
while
(
N
>
15
);
double
distance
[
N
];
double
speed
[
N
];
double
fdistance
[
N
];
printf
(
"Enter travel time:
\n
"
);
scanf
(
"%.lf"
,
&
t
);
AskInput
(
N
,
distance
,
speed
);
printf
(
"Object(s) distances:
\n
"
);
PrintInput
(
N
,
distance
);
printf
(
"
\n
Object(s) speeds:
\n
"
);
PrintInput
(
N
,
speed
);
printf
(
"
\n
Initial and final distances to target are:
\n
"
);
for
(
i
=
0
;
i
<
N
;
i
++
)
{
fdistance
[
i
]
=
FinDist
(
distance
[
i
],
speed
[
i
],
t
);
printf
(
"%lg
\t
%lg
\n
"
,
distance
[
i
],
fdistance
[
i
]);
}
Nailed
=
FinCounter
(
N
,
fdistance
);
printf
(
"%d object(s) has reached its target"
,
Nailed
);
return
0
;
}
void
AskInput
(
int
N
,
double
distance
[
N
],
double
speed
[
N
])
{
int
i
;
printf
(
"Enter object's distances and their speed:
\n
"
);
for
(
i
=
0
;
i
<
N
;
i
++
)
{
scanf
(
"%.1f %.1f"
,
&
distance
[
i
],
&
speed
[
i
]);
}
}
void
PrintInput
(
int
N
,
double
input
[
N
])
{
int
i
;
for
(
i
=
0
;
i
<
N
;
i
++
)
{
printf
(
"%.1f "
,
input
[
i
]);
}
}
double
FinDist
(
double
distance
,
double
speed
,
double
time
)
{
double
Fdistance
;
Fdistance
=
(
distance
-
(
speed
*
time
));
if
(
Fdistance
<
0
)
{
Fdistance
=
0
;
}
if
(
distance
<
0
)
{
Fdistance
=
0
;
}
return
Fdistance
;
}
int
FinCounter
(
int
N
,
double
fdistance
[
N
])
{
int
Counter
=
0
;
int
i
;
for
(
i
=
0
;
i
<
N
;
i
++
)
{
if
(
fdistance
[
i
]
==
0
)
{
Counter
++
;
}
}
return
Counter
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment