SKETCH TO ROLL 2 DICE #include < stdio.h > #include < stdlib.h > #include < math.h > int main( void ) { int num = 0 , steps = 0 , dice_1 = 0 , dice_2 = 0 , sum = 0 , counts = 0 ; float percentage; printf( "Number of throws" ); scanf( " %d" , &num); while (num > steps){ dice_1= rand() % 7 ; printf( " %i " , dice_1); dice_2 = rand() % 7 ; printf( " %i \n" , dice_2); sum = dice_1+dice_2; printf( " %i \n" , sum); steps ++; if (sum == 8 ){ counts ++;} } percentage = ( float )counts/num; printf( "Percentage of 8s: %2.3f percent" , percentage); return 0 ; }
Posts
Showing posts from September, 2018
Homework Number 6
- Get link
- X
- Other Apps
/* This program determines the distance between two points */ /* that are specified with latitude and longitude values */ /* that are in the Northern Hemisphere. */ #include < stdio.h > #include < math.h > #define PI 3.141593 int main( void ) { /* Declare variables and function prototype. */ double lat1, long1, lat2, long2; char again = 'y' ,lat1_d, long1_d, lat2_d, long2_d; double gc_distance( double lat1, double long1, double lat2, double long2); /* Get locations of two points. */ while (again == 'y' ){ printf( "Enter latitude (N/S)and longitude (E/W) " ); printf( "for location 1: \n" ); scanf( "%lf %s %lf %s" ,&lat1, &lat1_d, &long1, &long1_d); if (lat1_d == 's' || 'S' ){ lat1 = ...
Homework Number 5
- Get link
- X
- Other Apps
#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);...
Homework Number 4
- Get link
- X
- Other Apps
OPEN JET MODIFICATIONS /* This code will allow you to calculate the acceleration and velocity of a jet with a parameter of time input. It will allow you to choose your output and input unit preference */ #include < stdio.h > #include < math.h > int main( void ) { /* Declare variables. */ char input_method, output_method, more = 'y' ; double itime, velocity, acceleration, minutes, velocity_feet_sec, velocity_feet_min, acceleration_feet_sec, acceleration_feet_min; /* Get time value from the keyboard. */ while (more == 'y' ){ printf( "Choose input method: (s)econds/(m)inutes" ); scanf( " %c" , &input_method); printf( "Choose output method: (m)eters/sec, (f)eet/sec, feet/m(i)nute" ); scanf( " %c" , &output_method); if (input_method == 'm' ){ printf( "Enter new time value in minutes: \n" ); scanf( " %lf" , &minutes); itime = minutes* 60...