Distance Calculator (Motion)
Calculates distance (s) using the equation of motion s = ut + ½at² over a time range.
#include<stdio.h>
#include<math.h>
int main()
{
printf("INSTRUCTIONS: Enter initial velocity (u), acceleration (a), start time (t1), end time (t2), and time interval (t).\n");
float i,a,u,t,t1,t2,s;
printf("enter the value of u: ");
scanf("%f",&u);
printf("enter the value of a: ");
scanf("%f",&a);
printf("enter the value of t1: ");
scanf("%f",&t1);
printf("enter the value of t2: ");
scanf("%f",&t2);
printf("enter the value of t: ");
scanf("%f",&t);
for(i=t1;i<=t2;i=i+t)
{
s=(u*i)+(0.5*a*i*i);
printf("The value of s is %f\n",s);
}
return 0;
}Distance Calculator (Motion) — Free C, Java Code Example
Calculates distance (s) using the equation of motion s = ut + ½at² over a time range. This free code example is available in C, Java and can be copied and run immediately — no account or signup required. Use the language tabs above to switch between implementations.
How to Use This Code
- Select your language — click the language tab (C, Java, C++, or Python) above the code viewer.
- Copy the code — use the copy button in the top-right corner of the code block.
- Run it — paste into a file with the correct extension (.c, .java, .cpp, .py), compile, and run using your terminal or IDE.
- Follow the on-screen instructions in the terminal to provide any required inputs.
Frequently Asked Questions
What does this program do?
Calculates distance (s) using the equation of motion s = ut + ½at² over a time range.
Which languages is it available in?
Available in C, Java. Switch between implementations using the tabs at the top of the code viewer.
How do I run this code?
Copy the code, save it with the right file extension (.c, .java, .cpp, or .py), then compile or run it with your installed compiler or interpreter (GCC, JDK, G++, Python 3).
Is this code free?
Yes — free to view, copy, and use. No account required.