Commit 67c703f9 by chazog

Upload New File

parent 781257d9
Showing with 93 additions and 0 deletions
#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("\nObject(s) speeds:\n");
PrintInput(N, speed);
printf("\nInitial 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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment