Posts

Showing posts from September, 2017

Homework 7

Image
1. Write a program to simulate an experiment rolling two six-sided “fair” dice. Allow the user to enter the number of rolls of the dice to simulate. What percentage of the time does the sum of the dots on the dice equal 8 in the simulation? 2. A convenient approximation for computing the factorial n! for large values of n is given by the Stirling formula:

Homework 6

Image
1,2 /*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-*/ /*  This program determines the distance between two points    */ /*  that are specified with latitude and longitude values      */ //Yunfei Pan #include <stdio.h> #include <math.h> #define PI 3.141593 int main(void) { /*  Declare variables and function prototype.  */ double lat1, long1, lat2, long2; double gc_distance(double lat1,double long1, double lat2,double long2); /*  Get locations of two points.  */ printf("Enter latitude north and longitude west "); printf("for location 1: \n"); scanf("%lf %lf",&lat1,&long1); printf("Enter latitude north and longitude west "); printf("for location 2: \n"); scanf("%lf %lf",&lat2,&long2); /*  Print great circle distance.  */ printf("Great Circle Distance: %.0f miles \n", gc_distance(lat1,long1,lat2,long2)); /*  Exit program.  */ return 0; } /*–––...

Homework 5

i.Modify the program so that it finds the maximum crest and the minimum trough for the combined waves. // Implement the pseudocode //Yunfei Pan #include<stdio.h> #include<math.h> #include<assert.h> int main() #define PI 3.1415926 {   //initial   double p1,p2,h1,h2,w1,w2,r=0,t,l1,l2,r1=0;   //input   printf("Enter integer wave period (s) and wave height (ft)\nfor wave 1:\n");   scanf("%lf %lf",&p1,&h1);   assert(p1>=0&&h1>=0);   printf("Enter integer wave period (s) and wave height (ft)\nfor wave 2:\n");   scanf("%lf %lf",&p2,&h2);   assert(p2>=0&&h2>=0);   t=p1*p2/200;   //wave length   l1=5.13*p1*p1;   l2=5.13*p2*p2;     //max hight   for (int i=1;i<=200;i++)   {     w1=h1/2*sin(2*PI*t*i/p1);     w2=h2/2*sin(2*PI*t*i/p2);     if((w1+w2)>r)       r=w1+w2;  ...

Homework4

2. a=7500 3. const int BLED = 9; //Blue LED on Pin 9 const int GLED = 10; //Green LED on Pin 10 const int RLED = 11; //Red LED on Pin 11 const int BUTTON1 = 2; //The Button is connected to pin 2 const int BUTTON2 = 3; const int BUTTON3 = 4; const int BUTTON4 = 5; boolean lastButton1 = LOW; boolean lastButton2 = LOW; boolean lastButton3 = LOW; boolean lastButton4 = LOW;//Last Button State boolean currentButton1 = LOW; boolean currentButton2 = LOW; boolean currentButton3 = LOW; boolean currentButton4 = LOW;//Current Button State int ledMode = 0;//Cycle between LED states int bnk = 0; void setup() {   pinMode (BLED, OUTPUT); //Set Blue LED as Output   pinMode (GLED, OUTPUT); //Set Green LED as Output   pinMode (RLED, OUTPUT); //Set Red LED as Output   pinMode (BUTTON1, INPUT);   pinMode (BUTTON2, INPUT);   pinMode (BUTTON3, INPUT);   pinMode (BUTTON4, INPUT); //Set button as input (not required...

Homework3

Image
Water Salinity modifications 1. 2 Modify the program so that it converts and prints the new temperature in degrees Centigrade. 3.Suppose that the data used with the program contained values with the degrees in Centigrade. Would the program need to be changed? Explain. It does not need to be changed since the equation is same. 4. Open Jet 1. 2. 3.

Lab2

Image

Homework2

Image