When a ball is thrown with a speed U m/s at an angle of T radians
with the horizontal, the horizontal distance travelled or range,
R metres, is given by:-
R = U * U * sin( 2 * T ) / 9.8
Write a C program to produce a table showing the range of the ball
for speeds in the range 10 to 40 m/s in steps of 10 m/s and angles
with the horizontal in the range 15 to 75 degrees in steps of 15
degrees. The output from the program should be as follows:-
*****************************************
* Speed(m/s)* Angle(degrees) * Range(m) *
*****************************************
* 10 * 15 * *
* 10 * 30 * *
* 10 * 45 * *
* 10 * 60 * *
* 10 * 75 * *
* 20 * 15 * *
* 20 * 30 * *
* 20 * 45 * *
* 20 * 60 * *
* 20 * 75 * *
* 30 * 15 * *
* 30 * 30 * *
* 30 * 45 * *
* 30 * 60 * *
* 30 * 75 * *
* 40 * 15 * *
* 40 * 30 * *
* 40 * 45 * *
* 40 * 60 * *
* 40 * 75 * *
*****************************************
Hint: 180 degrees = 3.1416 radians
That's my question I have for class in 2 hours and i'm getting pretty worried i'm not going to be able to figure it out before getting there.
For those that are wondering why i've left it so soon before class it's because i've been trying to revise through the very basics of coding the last few days. Effectively i've jumped into a class that wasn't the beginners class, I messed up so i'm playing a lot of catch up.
Below is the code that I have, it's wrong....very wrong, I just don't understand how. Again, I am very new to coding hence why what i'm asking may sound a bit dumb.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#include<stdio.h>
#include<math.h>
int main ()
{
int speed = 10;
int angle = 15;
int range = 0;
for (int i =1 ;i<10;i++)
{
printf("%d\n", i);
}
printf ("speed angle \n");
temp_loop:
range = speed * speed * sin(2*angle)/9.8;
printf ("%2d\t = %2d\n", speed, angle, range);
speed+=10;
if (speed <= 40 ) goto temp_loop;
}
|