For each of the programs assigned below, submit the following: .Hard copy of the
ID: 2249355 • Letter: F
Question
For each of the programs assigned below, submit the following: .Hard copy of the source code. . Hard copy of sample executions (black or, preferably, white screen) . Copy of the source code (.c ) saved as an electronic attachment Assignment 8 located in Canvas under Assignments Observe the usual guidelines regarding the initial comment section, indenting, and so on. In addition, Indent statements within loops 1. The height h of a ball thrown upward at an angle A with initial velocity vo is given by the following formula: hvo sin( A)- Suppose in a given situation a table of values of time t and height h are to be printed in a table beginning at time 0 and continuing at intervals of 0.05 second until the ball reaches the ground. Use preprocessor commands to define g with a value of 9.81 and pi with a value of 3.14159. In function main, prompt the user to input first the initial velocity v0 (a value between 10 and 15 meters per second inclusive) and then the angle of launch (a value between 30 and 60 degrees inclusive). Use while data validation loops to assure that the initial velocity and angle of launch are each in the proper range. (Hint: You will validate each variable separately) Call a function to print a labeled table of values of time t and height h, beginning at time 0 and continuing at intervals of 0.05 second until the ball reaches the ground The function will have as parameters the initial velocitv and the angle of launch and will not return a value. In the function use a while loop and print the values one line at a time within the loop, placing time in the column on the left and height in the column on the right. Do not print any negative values of height. Use 2 digits after the decimalExplanation / Answer
Answer:- The C code for measuring the height of the ball is written below-
/* Program to measure the height of a ball thrown at angle A and with initial speed V */
#include<stdio.h>
#include<math.h>
#define g 9.81
#define pi 3.14159
void cal_height(float, float); /* function prototype */
int main(void)
{
float velo1, ang1;
printf("Enter the initial velocity in m/s:");
scanf("%f", &velo1);
while(velo1 < 15 && velo1 > 10)
{
printf("Enter the value of angle in degree:");
scanf("%f", &ang1);
while(ang1 < 60 && ang1 > 30)
{
cal_height(velo1, ang1);
return 0;
}
printf("Entered angle is not in proper range, hence exiting ");
return 1;
}
printf("Entered velocity is not in proper range, hence exiting ");
return 1;
}
void cal_height(float vel1, float ang1)
{
float height1 = 0, time1 = 0, ang_rad1;
ang_rad1 = (ang1*pi)/180;
while(1)
{
height1 = (vel1*time1*sin(ang_rad1)) - (0.5*g*time1*time1);
time1 = time1 + 0.05;
if(height1 >= 0)
printf(" %1.2f %1.2f ", time1, height1);
else
exit(0);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.