1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main()
{
int n, count=0, B2=1, i=0, input=2;
float delta_t, xl, yloop, v, m=400, r=0;
float *f_dragx=NULL;
float *f_dragy=NULL;
float *x=NULL;
float *y=NULL;
float *vx=NULL;
float *vy=NULL;
printf("\n Kindly insert down delta t \t");
scanf("%f", &delta_t);
while(input!=0)
{
vx = (float*) realloc (vx, count * sizeof(float));
vy = (float *) realloc (vy, count * sizeof(float));
x = (float*) realloc (x, count * sizeof(float));
y = (float *) realloc (y, count * sizeof(float));
f_dragx= (float*) realloc (f_dragx, count * sizeof(float));
f_dragy= (float *) realloc (f_dragy, count * sizeof(float));
printf("Enter the initial value of x\n");
scanf("%f", &x[count]);
printf("Enter the initial value of y\n");
scanf("%f", &y[count]);
printf("Enter the initial value of vx\n");
scanf("%f", &vx[count]);
printf("Enter the initial value of vy\n");
scanf("%f", &vy[count]);
v=pow(vx[count]* vx[count]+ vy[count]* vy[count], 0.5);
f_dragx[count]=-(B2)*v*vx[count];
printf("The initial value of horizontal drag force is %f\n", f_dragx[count]);
f_dragy[count]=-(B2)*v*vy[count];
printf("The initial value vertical drag force is %f \n\n\n", f_dragy[count]);
count++;
while (yloop>=0)
{
vx = (float*) realloc (vx, count * sizeof(float));
vy = (float *) realloc (vy, count * sizeof(float));
x = (float*) realloc (x, count * sizeof(float));
y = (float *) realloc (y, count * sizeof(float));
f_dragx= (float*) realloc (f_dragx, count * sizeof(float));
f_dragy= (float *) realloc (f_dragy, count * sizeof(float));
x[count]=x[count-1]+vx[count-1]*delta_t;
y[count]=y[count-1]+vy[count-1]*delta_t;
vx[count]=vx[count-1]+(f_dragx[count]/m)*delta_t;
vy[count]=vy[count-1]+(-9.8+(f_dragy[count]/m))*delta_t;
v=pow(vx[count]* vx[count]+ vy[count]* vy[count], 0.5);
f_dragx[count]=-(B2)*v*vx[count];
f_dragy[count]=-(B2)*v*vy[count];
yloop=y[count];
printf(" %d %f %f %f %f %f %f\n", count, x[count],y[count],vx[count],vy[count],f_dragx[count],f_dragy[count]);
count++;
}
r=(-y[count-1])/(y[count]);
xl=((x[count-1]+r*x[count])/(r+1));
printf("To restart the program, hit any positive integer other than 0, otherwise, hit 0\n");
scanf("%d", &input);
}
return 0;
}
|