Write a C++ program to calculate the maximum height when the user gives the angle (in degrees). The given below is the equation to calculate the maximum height.
v = 10.568 (initial velocity), g = 9.8 (acceleration due to gravity), θ = angle of the initial velocity from horizontal plane in radians and H = maximum height
Note: Assign the above values for v, g and PI. Consider the g (acceleration due to gravity) is a constant.
#include<iostream>
#include<math.h>
using namespace std;
float computingSin(float number) {
float result = 0.0001, denom, sin_x, sin_val;
number = number * (3.142 / 180.0); //Changing the angle to radians
float t= number;
sin_x = number;
sin_val = sin(number);
int x = 1;
do {
denom = 2 * x * (2 * x + 1);
t = -t * number * number / denom;
sin_x = sin_x + t;
x = x + 1;
} while (result <= fabs(sin_val - sin_x));
return sin_x;
}
int main(){
cout<<"Enter the starting angle\n";
int angle;
cin>>angle;
float v0 = 10.568;
for(int i=angle; i<=20; i++){
float H = ((v0 * v0) * pow(computingSin(i), 2)) / (2 * 9.8);
cout<<"Maximum height for angle "<< i <<" is: "<<H<<endl;
}
}
Comments
Leave a comment