Homework Number 5

#include <stdio.h>
#include <math.h>
/* This program will convert Feet/sec to Miles/Hour, and print a chart with increments of 5 */

int main(void) {
float mph = 0;
int i = 0, x;
char again = 'y';
while (again == 'y'){

 printf("Feet/sec  Miles/hour \n");
 x = i;
 for (i; i<(105+x); i = i+ 5)
 {
  mph = 0.6818*i;
  printf( "%6i %12.5f \n", i, mph); }
 printf("Another 10 steps? (y/n)");
 scanf(" %s", &again);
}

return 0;
}

WAVES CODE
#include <stdio.h>
#include <math.h>
#define PI 3.14159265358979323846

int main(void) {
float w1_p, w1_h, w1_wl, w2_p, w2_h, w2_wl, num_points, time_increment, w1_f, w2_f, phase;
char more = 'y', input_method;
while (more == 'y') {
printf("Input: (f)/s or (m)/s");
scanf(" %c", &input_method);
printf("Enter integer wave period (s) and wave height(%c) \n", input_method );
scanf(" %f %f", &w1_p, &w1_h);
printf("Enter integer wave period for wave2 (s), and wave height for wave2 (%c) \n", input_method);
scanf(" %f %f", &w2_p, &w2_h);
w1_wl = 5.13*(w1_p*w1_p);
w2_wl = 5.13*(w2_p*w2_p);
printf("Wavelength of wave 1: %.2f \n", w1_wl);
printf("Wavelength of wave 2: %.2f \n", w2_wl);
if (input_method == 'm'){
w1_h =3.28*w1_h;
w2_h = 3.28*w2_h;
}

printf("Number of data points to compute?");
scanf(" %f", &num_points);
time_increment = (w1_p*w2_p)/num_points;
float t = 0;
float steps = 0;
float sum = 0;
float highest = 0;
printf("Phase shift for wave 2? (in radians): ");
scanf(" %f", &phase );
w1_f = 1/(w1_p);
w2_f = 1/(w2_p);
/* These lines will compute and print the combined max height over given interval */
while (steps <= num_points){
sum = w1_h*(sin(2*PI*w1_f*t)) + w2_h*(sin(2*PI*w2_f*t + phase));
if (sum >= highest){
highest = sum;
}
t = t+ time_increment;
steps = steps+1;
}
printf("Maximum combined wave height (feet): %2.3f \n", highest);
printf (" Max crest and min trough: % 3.2f \n", highest/2);
/* These lines will compute and print the height at given times */
float num_boi, step_boi = 0, time_boi = 0, height_boi;
printf("Number of times you want to find specific height:");
scanf(" %f", &num_boi);
while (step_boi < num_boi ){
printf("Specific time to find maximum height for?");
scanf(" %f", &time_boi);
height_boi = w1_h*(sin(2*PI*w1_f*time_boi)) + w2_h*(sin(2*PI*w2_f*time_boi + phase));
printf("The height at %2.3f seconds is %2.3f feet \n", time_boi, height_boi );
step_boi = step_boi +1 ;
}
printf("Run program again? (y/n)");
scanf(" %c", &more);

}

return 0;
}

Comments

Popular posts from this blog

Seismic Code

Strings

BMP180 Code + Library to SD card