Write a C++ program to calculate time dilation (t) in motion, when the speed of the moving objects (v) is given by the user. The given below is the equation to calculate the time dilation.
v = speed of the moving object, c = 15000 ms-1(speed of light), and t0 = 75 s (time in observers own frame of reference)
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int v, c,t0;
cout<<"Enter the speed of the moving object: ";
cin>>v;
if(v>=100 & v<=200){
float t=75/pow((1-pow((v-89),2)/(15*15)),0.2);
cout<<"time dilation is: "<<t<<"s";
}
else if(v<100){
cout<<"The speed is too low ";
}
else{
cout<<"Speed is too high";
}
}
Comments
Leave a comment