Wednesday, September 19, 2018

Homework 7

Factorials
/* This program compares a recursive function and */
/* a nonrecursive function for computing factorials. */
#include <stdio.h>
#include <math.h>
int main(void)
#define PI 3.141593
#define e 2.718281
{
/* Declare variables and function prototypes. */
double n;
double factorial(double k);
double factorial_r(double k);
double n_fact(double k);
/* Get user input. */
printf("Enter positive integer: \n");
scanf("%lf",&n);
/* Compute and print factorials. */
printf("Nonrecursive: %lf! = %lf \n",n,factorial(n));
printf("Recursive: %lf! = %lf \n",n,factorial_r(n));
printf("Sterling: %lf! = %lf \n",n,n_fact(n));
/* Exit program. */
return 0;
}
/* This function computes a factorial with a loop. */
double factorial(double k)
{
/* Declare variables. */
double j;
long term;
/* Compute factorial with multiplication. */
term = 1;
for (j=2; j<=k; j++)
term *=j;
/* Return factorial value. */
return term;
}
/* This function computes a factorial recursively. */
double factorial_r(double k)
{
/* Use recursive reference until k=0. */
if (k == 0)
return 1;
else
return k*factorial_r(k-1);
}
/* This function computes a factorial using Sterling Formula*/
double n_fact(double n)
{
return sqrt(2*PI*n)*pow(n/e, n);
}

Random Dice Rolls
/* This program generates and prints ten random */
/* integers between user-specified limits. */
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
/* Declare variables and function prototype. */
unsigned int seed;
int a=1, b=6, k, dice1, dice2, d;
double dice_percent, dicecounter;
int rand_int(int a,int b);
/* Get seed value and interval limits. */
printf("Enter a positive integer seed value: \n");
scanf("%u",&seed);
printf("Enter the number of rolls of the dice to simulate: \n");
scanf("%u",&d);
srand(seed);
/* Generate and print ten random numbers. */
printf("\nRandom dice rolls of two dice: \n");
for (k=1; k<=d; k++)
{
dice1 = rand_int(a,b);
dice2 = rand_int(a,b);
if (dice1 + dice2 == 8)
{
dicecounter++;
}
printf("\nRoll #%i: %i, %i\n", k , dice1, dice2);
}
dice_percent = (dicecounter / d) * 100;
printf("\nPercentage of times that the values of the dice equaled 8: %.2f ", dice_percent);
/* Exit program. */
return 0;
}
/* This function generates a random integer */
/* between specified limits a and b (a<b). */
int rand_int(int a,int b)
{
return rand()%(b-a+1) + a;
}

Wednesday, September 12, 2018

Homework 5

/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
/* This program determines wavelengths and wave height of open seawater */
#include <stdio.h>
#include <math.h>
#define PI 3.141593
int main(void)
{
/* Declare variables. */
double w1_ht, w2_ht, w1_L, w2_L, s1, s2, s1_user, s2_user, sum, time_incre, wavemax=0, time=0, steps, w1_period, w2_period, p_shift, trough, time_mwh, wavemax_spec, in_step;

/* Read the periods and wave heights of the two waves to be combined. */
printf("This program is designed to determine the wavelengths for two seperate waves. It will also compute the maximum height of the two waves when combined.\n");
printf("\nEnter a value for the period of your 1st wave. \n");
scanf("%lf", &w1_period);
printf("Enter the height for your 1st wave in meters. \n");
scanf("%lf", &w1_ht);
printf("Enter a value for the period of your 2nd wave. \n");
scanf("%lf", &w2_period);
printf("Enter the height of your 2nd wave in meters. \n");
scanf("%lf", &w2_ht);
printf("Enter how many times you want data to be computed to determine wavelengths and wave heights.\n");
scanf("%lf", &in_step);
printf("Enter a phase shift for the second wave from the first wave in degrees.\n");
scanf("%lf", &p_shift);
printf("If you want, enter a time in seconds after zero you'd want the max wave height for. \n");
scanf("%lf", &time_mwh);


/*(Compute and print the wavelengths of the individual waves*/
w1_L = 5.13 * w1_period * w1_period;
w2_L = 5.13 * w2_period * w2_period;
time_incre = (1/in_step)*w1_period * w2_period;
printf("\nThe wavelength of wave 1: %3.3lf m\n", w1_L * 0.3048);
printf("The wavelength of wave 2: %3.3lf m\n", w2_L * 0.3048);

s1_user = (w1_ht * 0.5) * sin (2 * PI * (1/w1_period) * time_mwh);
s2_user = (w2_ht * 0.5) * sin ((2 * PI * (1/w2_period) * time_mwh)+ (p_shift * PI / 180));
wavemax_spec = s1_user + s2_user;

/*Compute 200 values of the sum of the two waves and determine the maximum value*/
for (steps = 0; steps <= in_step; steps++)
{
time = (steps*time_incre);
s1 = (w1_ht * 0.5) * sin (2 * PI * (1/w1_period) * time );
s2 = (w2_ht * 0.5) * sin ((2 * PI * (1/w2_period) * time) + (p_shift * PI / 180));
sum = s1 + s2;
if (sum >= wavemax)
{
wavemax = sum;
}
if (sum <= trough)
{
trough = sum;
}
}

/*Print the maximum value*/
printf("Maximum combined wave height: %3.3lf m\n", wavemax*2);
printf("Maximum crest height:%3.3lf m\n", wavemax);
printf("Minimum trough depth:%3.3lf m\n", trough);
if (time_mwh > 0)
{
printf("Max combined wave height at %3.3lf sec: %3.3lf m", time_mwh, wavemax_spec*2);
}
else;
/* Exit program. */
return 0;
}

TEMPERATURE SENSOR
//Potentiometer Reading Program
const int POT=0; //Pot on analog pin 0
const int RLED=11; //Red LED on Pin 11
const int BLED=9; //Blue LED on Pin 9
const int GLED=10; //Green LED on Pin 10
int val = 0; //variable to hold the analog reading from the POT
void setup()
{
Serial.begin(9600); //Start Serial Communication
}
void loop()
{
val = analogRead(POT); //Read one value from the POT
Serial.println(val); //Print it to the serial port
delay(500);

//HOT
if (val > 163)
{
digitalWrite(RLED, HIGH);
digitalWrite(GLED, LOW);
digitalWrite(BLED, LOW);
}
//Temperate
else if (val <163 && val > 146)
{
digitalWrite(RLED, LOW);
digitalWrite(GLED, HIGH);
digitalWrite(BLED, LOW);
}
//COLD
else if (val < 146)
{
digitalWrite(RLED, LOW);
digitalWrite(GLED, LOW);
digitalWrite(BLED, HIGH);
}

}

Tuesday, September 11, 2018

Homework 3

Linear Interpolate Seawater Temperatures from Salinity

/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
/* This program uses linear interpolation to */
/* compute the freezing temperature of seawater. */

#include <stdio.h>
#include <math.h>
int main(void)
{
/* Declare variables. */
double a, f_a, b, f_b, c, f_c;

/* Get user input from the keyboard. */
printf("Use ppt for salinity values. \n");
printf("Use degrees F for temperatures. \n");
printf("\nEnter first salinity and freezing temperature: \n");
scanf("%lf %lf",&a,&f_a);
printf("Enter second salinity and freezing temperature: \n");
scanf("%lf %lf",&c,&f_c);
printf("Enter new salinity: \n");
scanf("%lf",&b);

// Use linear interpolation to compute new freezing temperature.
f_b = f_a + (b-a)/(c-a)*(f_c - f_a);
/* Print new freezing temperature. */
printf("\nNew freezing temperature in degrees F: %4.3f \n",f_b);
return 0;
}
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/

Linear Interpolation of Seawater Temperatures in Centigrade

/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
/* This program uses linear interpolation to */
/* compute the freezing temperature of seawater. */
#include <stdio.h>
#include <math.h>
int main(void)
{
/* Declare variables. */
double a, f_a, b, f_b, c, f_c, f_b_centigrade;
/* Get user input from the keyboard. */
printf("Use ppt for salinity values. \n");
printf("Use degrees F for temperatures. \n");
printf("Enter first salinity and freezing temperature: \n");
scanf("%lf %lf",&a,&f_a);
printf("Enter second salinity and freezing temperature: \n");
scanf("%lf %lf",&c,&f_c);
printf("Enter new salinity: \n");
scanf("%lf",&b);

// Use linear interpolation to compute new freezing temperature.
f_b = f_a + (b-a)/(c-a)*(f_c - f_a);
f_b_centigrade = (f_b - 32)/1.8;

/* Print new freezing temperature. */
printf("New freezing temperature in degrees C: %4.3lf \n", f_b_centigrade);
return 0;
}
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/

Linear Interpolation of Salinity

/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
/* This program uses linear interpolation to */
/* compute the salinity of seawater at a certain temperature */
#include <stdio.h>
#include <math.h>
int main(void)
{
/* Declare variables. */
double a, f_a, b, f_b, c, f_c;

/* Get user input from the keyboard. */
printf("Use ppt for temperature values. \n");
printf("Use degrees F for temperatures. \n");
printf("\nEnter first freezing temperature and then salinity: \n");
scanf("%lf %lf",&a,&f_a);
printf("Enter second freezing temperature and then salinity: \n");
scanf("%lf %lf",&c,&f_c);
printf("Enter new temperature: \n");
scanf("%lf",&b);

// Use linear interpolation to compute new salinity.
f_b = f_a + (b-a)/(c-a)*(f_c - f_a);

/* Print new salinity. */
printf("\nNew salinity in parts per tenths: %4.2f \n",f_b);
return 0;
}
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/

Bouncy Buttons Lab

const int LED_9 = 9; //The LED is connected to pin 9 
const int BUTTON_2 = 2; //The Button is connected to pin 2 
const int LED_8 = 8; //The LED is connected to pin 9 
const int BUTTON_3 = 3; //The Button is connected to pin 2
 boolean lastButton_2 = LOW; //Variable containing the previous button state 
boolean currentButton_2 = LOW; //Variable containing the current button state 
boolean ledOn_9 = false; //The present state of the LED (on/off) 
boolean lastButton_3 = LOW; //Variable containing the previous button state 
boolean currentButton_3 = LOW; //Variable containing the current button state 
boolean ledOn_8 = false; //The present state of the LED (on/off) 

void setup() 
pinMode (LED_9, OUTPUT); //Set the LED pin as an output 
pinMode (BUTTON_2, INPUT); //Set button as input (not required) 
pinMode (LED_8, OUTPUT); //Set the LED pin as an output 
pinMode (BUTTON_3, INPUT); //Set button as input (not required) }

 /* Debouncing Function Pass it the previous button state, * and get back the current debounced button state.*/ 

boolean debounce_9(boolean last_9) 
   { 
      boolean current_9 = digitalRead(BUTTON_2); //Read the button state 
         if (last_9 != current_9) //if it's different… 
      { 
         delay(5); //wait 5ms 
         current_9 = digitalRead(BUTTON_2); //read it again 
         return current_9; //return the current value 
      }
    } 

boolean debounce_8(boolean last_8) 
   { 
      boolean current_8 = digitalRead(BUTTON_3); //Read the button state 
         if (last_8 != current_8) //if it's different… 
      { 
         delay(5); //wait 5ms 
        current_8 = digitalRead(BUTTON_3); //read it again 
        return current_8; //return the current value 
      }
    } 

void loop() 
currentButton_2 = debounce_9(lastButton_2); //read debounced state 
if (lastButton_2 == LOW && currentButton_2 == HIGH) //if it was pressed... 
ledOn_9 = !ledOn_9; //toggle the LED value } 
lastButton_2 = currentButton_2; //reset button value 
digitalWrite(LED_9, ledOn_9); //change the LED state 
currentButton_3 = debounce_8(lastButton_3); //read debounced state 
if (lastButton_3 == LOW && currentButton_3 == HIGH) //if it was pressed... 
ledOn_8 = !ledOn_8; //toggle the LED value 
lastButton_3 = currentButton_3; //reset button value 
digitalWrite(LED_8, ledOn_8); //change the LED state 
}

Homework 2

Height Estimates from in to ft based on Bone Lengths

#include <stdio.h>
#include <math.h>
int main(void)
{

/* Declare variables. */
double femur, humerus, femur_ht_f, femur_ht_m, humerus_ht_f,
humerus_ht_m;
/* Get user input from the keyboard. */
printf("Enter Values in Inches. \n");
printf("Enter femur length: \n");
scanf("%lf",&femur);
printf("Enter humerus length: \n");
scanf("%lf",&humerus);

/* Compute height estimates. */
femur_ht_f = (femur*1.94 + 28.7) / 12;
femur_ht_m = (femur*1.88 + 32) / 12;
humerus_ht_f = (humerus*2.8 + 28.2) / 12;
humerus_ht_m = (humerus*2.9 + 27.9) / 12;
/* Print height estimates. */

printf("\nHeight Estimates in Feet \n");
printf("\nFemur Female Estimate: %5.1f ft\n",femur_ht_f);
printf("Femur Male Estimate: %5.1f ft\n",femur_ht_m);
printf("\nHumerus Female Estimate: %5.1f ft\n",humerus_ht_f);
printf("Humerus Male Estimate: %5.1f ft\n",humerus_ht_m);

/* Exit program. */
return 0;
}


Height Estimates in ft based on Bone Lengths

#include <stdio.h>
#include <math.h>
int main(void)
{

/* Declare variables. */
double femur, humerus, femur_ht_f, femur_ht_m, humerus_ht_f,
humerus_ht_m;
/* Get user input from the keyboard. */

printf("Enter Values in Feet. \n");
printf("Enter femur length: \n");
scanf("%lf",&femur);
printf("Enter humerus length: \n");
scanf("%lf",&humerus);

/* Compute height estimates. */
femur_ht_f = ((femur*1.94*12) + 28.7)/12;
femur_ht_m = ((femur*1.88*12) + 32)/12;
humerus_ht_f = ((humerus*2.8*12) + 28.2)/12;
humerus_ht_m = ((humerus*2.9*12) + 27.9)/12;

/* Print height estimates. */
printf("\nHeight Estimates in Feet \n");
printf("\nFemur Female Estimate: %5.1f ft\n",femur_ht_f);
printf("Femur Male Estimate: %5.1f ft\n",femur_ht_m);
printf("\nHumerus Female Estimate: %5.1f ft\n",humerus_ht_f);
printf("Humerus Male Estimate: %5.1f ft\n",humerus_ht_m);

/* Exit program. */
return 0;
}

Height Estimates in in and ft based on Bone Lengths

#include <stdio.h>
#include <math.h>
int main(void)

{
/* Declare variables. */
double femur, humerus, femur_ht_f_in, femur_ht_m_in, humerus_ht_f_in,
humerus_ht_m_in, femur_ht_f_ft, femur_ht_m_ft, humerus_ht_f_ft,
humerus_ht_m_ft;

/* Get user input from the keyboard. */
printf("Enter Values in Inches. \n");
printf("Enter femur length: \n");
scanf("%lf",&femur);
printf("Enter humerus length: \n");
scanf("%lf",&humerus);

/* Compute height estimates in inches. */
femur_ht_f_in = (femur*1.94 + 28.7);
femur_ht_m_in = (femur*1.88 + 32);
humerus_ht_f_in = (humerus*2.8 + 28.2);
humerus_ht_m_in = (humerus*2.9 + 27.9);

/* Compute height estimates in feet. */
femur_ht_f_ft = (femur*1.94 + 28.7) / 12;
femur_ht_m_ft = (femur*1.88 + 32) /12;
humerus_ht_f_ft = (humerus*2.8 + 28.2) / 12;
humerus_ht_m_ft = (humerus*2.9 + 27.9) / 12;

/* Print height estimates. */
printf("\nHeight Estimates in Inches and also Feet\n");
printf("\nFemur Female Estimate: %5.1f in /%5.2f ft \n", femur_ht_f_in, femur_ht_f_ft);
printf("Femur Male Estimate: %5.1f in /%5.2f ft \n", femur_ht_m_in, femur_ht_m_ft);
printf("\nHumerus Female Estimate: %5.1f in /%5.2f ft\n", humerus_ht_f_in, humerus_ht_f_ft);
printf("Humerus Male Estimate: %5.1f in /%5.2f ft\n", humerus_ht_m_in, humerus_ht_m_ft);

/* Exit program. */
return 0;
}

Height Estimates in in/ft based on Bone Lengths

#include <stdio.h>
#include <math.h>
int main(void)
{

/* Declare variables. */
double femur_in, femur_ft, humerus_in, humerus_ft, femur_ht_f_in, femur_ht_m_in, humerus_ht_f_in,
humerus_ht_m_in, femur_ht_f_ft, femur_ht_m_ft, humerus_ht_f_ft,
humerus_ht_m_ft;

/* Get user input from the keyboard. */
printf("Enter Values in Inches. \n");
printf("Enter femur length: \n");
scanf("%lf",&femur_in);
printf("Enter humerus length: \n");
scanf("%lf",&humerus_in);
printf("\nEnter Values in Feet. \n");
printf("Enter femur length: \n");
scanf("%lf",&femur_ft);
printf("Enter humerus length: \n");
scanf("%lf",&humerus_ft);

/* Compute height estimates in inches. */
femur_ht_f_in = (femur_in*1.94 + 28.7);
femur_ht_m_in = (femur_in*1.88 + 32);
humerus_ht_f_in = (humerus_in*2.8 + 28.2);
humerus_ht_m_in = (humerus_in*2.9 + 27.9);

/* Compute height estimates in feet. */
femur_ht_f_ft = ((femur_ft*12)*1.94 + 28.7);
femur_ht_m_ft = ((femur_ft*12)*1.88 + 32);
humerus_ht_f_ft = ((humerus_ft*12)*2.8 + 28.2);
humerus_ht_m_ft = ((humerus_ft*12)*2.9 + 27.9);

/* Print height estimates. */
printf("\nHeight Estimates in Inches and then Feet\n");
printf("\nFemur Female Estimate: %5.1f in / %5.2f ft \n", femur_ht_f_in, femur_ht_f_ft);
printf("Femur Male Estimate: %5.1f in / %5.2f ft \n", femur_ht_m_in, femur_ht_m_ft);
printf("\nHumerus Female Estimate: %5.1f in / %5.2f ft\n", humerus_ht_f_in, humerus_ht_f_ft);
printf("Humerus Male Estimate: %5.1f in / %5.2f ft\n", humerus_ht_m_in, humerus_ht_m_ft);

/* Exit program. */
return 0;
}

Height Estimates in cm based on Bone Lengths

#include <stdio.h>
#include <math.h>
int main(void)
{

/* Declare variables. */
double femur, humerus, femur_ht_f, femur_ht_m, humerus_ht_f, humerus_ht_m;

/* Get user input from the keyboard. */
printf("Enter Values in Centimeters. \n");
printf("Enter femur length: \n");
scanf("%lf",&femur);
printf("Enter humerus length: \n");
scanf("%lf",&humerus);

/* Compute height estimates in centimeters. */
femur_ht_f = ((femur/2.54)*1.94 + 28.7);
femur_ht_m = ((femur/2.54)*1.88 + 32);
humerus_ht_f = ((humerus/2.54)*2.8 + 28.2);
humerus_ht_m = ((humerus/2.54)*2.9 + 27.9);

/* Print height estimates. */
printf("\nHeight Estimates in Centimeters\n");
printf("\nFemur Female Estimate: %5.2f cm\n", femur_ht_f*2.54);
printf("Femur Male Estimate: %5.2f cm\n", femur_ht_m*2.54);
printf("\nHumerus Female Estimate: %5.2f cm\n", humerus_ht_f*2.54);
printf("Humerus Male Estimate: %5.2f cm\n", humerus_ht_m*2.54);

/* Exit program. */
return 0;
}

Molecular weight of glycine

#include <stdio.h>
#include <math.h>
int main(void)
{

/* Declare variables. */
double oxygen=15.9994, carbon=12.011, nitrogen=14.00674, sulfur=32.066, hydrogen=1.00794, weight_glycine;

/* Compute weight of glycine. */
weight_glycine = 2*oxygen + 2*carbon + nitrogen + 5*hydrogen;

/* Print weight. */
printf("The molecular weight for Glycine is %.4lf amu.", weight_glycine);

/* Exit program. */
return 0;
}

Molecular Weights of Glutamic and Glutamine

#include <stdio.h>
#include <math.h>
int main(void)
{

/* Declare variables. */
double oxygen=15.9994, carbon=12.011, nitrogen=14.00674, sulfur=32.066, hydrogen=1.00794, weight_glutamic, weight_glutamine;

/* Compute weight of glutamic and glutamine. */
weight_glutamic = 4*oxygen + 5*carbon + nitrogen + 8*hydrogen;
weight_glutamine = 3*oxygen + 5*carbon + 2*nitrogen + 10*hydrogen;

/* Print weight. */
printf("The molecular weight for Glutamic is %.4lf amu.\n", weight_glutamic);
printf("\nThe molecular weight for Glutamine is %.4lf amu.", weight_glutamine);

/* Exit program. */
return 0;
}

Molecular Weight of am Amino Acid

#include <stdio.h>
#include <math.h>
int main(void)
{

/* Declare variables. */
double oxygen=15.9994, carbon=12.011, nitrogen=14.00674, sulfur=32.066, hydrogen=1.00794, weight_amino, o_num, c_num, n_num, s_num, h_num;

/*Input number of atoms of amino acid*/
printf("Enter the number of atoms for each element of your amino acid. \n");
printf("Enter number of oxygen atoms: \n");
scanf("%lf",&o_num);
printf("Enter number of carbon atoms: \n");
scanf("%lf",&c_num);
printf("Enter number of nitrogen atoms: \n");
scanf("%lf",&n_num);
printf("Enter number of sulfur atoms: \n");
scanf("%lf",&s_num);
printf("Enter number of hydrogen atoms: \n");
scanf("%lf",&h_num);

/* Compute weight of amino acid. */

weight_amino = (o_num*oxygen) + (c_num*carbon) + (n_num*nitrogen) + (s_num*sulfur) + (h_num*hydrogen);

/* Print weight. */
printf("\nThe molecular weight for your amino acid is %.4lf amu.", weight_amino);

/* Exit program. */
return 0;
}

Average Weight of Elements of Amino Acid

#include <stdio.h>
#include <math.h>
int main(void)
{

/* Declare variables. */
double oxygen=15.9994, carbon=12.011, nitrogen=14.00674, sulfur=32.066, hydrogen=1.00794, o_num, c_num, n_num, s_num, h_num, sum_atoms, average_weight;

/*Input number of atoms of amino acid*/
printf("Enter the number of atoms for each element of your amino acid. \n");
printf("Enter number of oxygen atoms: \n");
scanf("%lf",&o_num);
printf("Enter number of carbon atoms: \n");
scanf("%lf",&c_num);
printf("Enter number of nitrogen atoms: \n");
scanf("%lf",&n_num);
printf("Enter number of sulfur atoms: \n");
scanf("%lf",&s_num);
printf("Enter number of hydrogen atoms: \n");
scanf("%lf",&h_num);

/* Compute weight of amino acid. */
sum_atoms = o_num + c_num + n_num + s_num + h_num;

average_weight = ((o_num*oxygen) + (c_num*carbon) + (n_num*nitrogen) + (s_num*sulfur) + (h_num*hydrogen)) / sum_atoms;

/* Print weight. */
printf("\nThe average weight of the elements for your amino acid is %.4lf amu.", average_weight);

/* Exit program. */
return 0;
}

Kitt Nightrider Blinking

void setup()
{
pinMode(10,OUTPUT);
pinMode(9,OUTPUT);
pinMode(8,OUTPUT);
pinMode(7,OUTPUT);
pinMode(6,OUTPUT); //Initialize Pins
}
void loop()
{
digitalWrite(10,HIGH); //Set the LED
On delay(100); //Wait for 100 ms
digitalWrite(10,LOW); //Set the LED Off

digitalWrite(9,HIGH); //Set the LED On
delay(100); //Wait for 100 ms
digitalWrite(9,LOW); //Set the LED Off

digitalWrite(8,HIGH); //Set the LED On
delay(100); //Wait for 100 ms
digitalWrite(8,LOW); //Set the LED Off

digitalWrite(7,HIGH); //Set the LED On
delay(100); //Wait for 100 ms
digitalWrite(7,LOW); //Set the LED Off

digitalWrite(6,HIGH); //Set the LED On
delay(100); //Wait for 100 ms
digitalWrite(6,LOW); //Set the LED Off

digitalWrite(7,HIGH); //Set the LED On
delay(100); //Wait for 100 ms
digitalWrite(7,LOW); //Set the LED Off

digitalWrite(8,HIGH); //Set the LED On
delay(100); //Wait for 100 msms
digitalWrite(8,LOW); //Set the LED Off

digitalWrite(9,HIGH); //Set the LED On
delay(100); //Wait for 100 ms
digitalWrite(9,LOW); //Set the LED Off

Homework 1

Meters to Miles

#include <stdio.h>
#include <math.h>
int main(void)
{

/* Declare and initialize variables. */
double dist_meter, dist_mile;

/* Get user input from the keyboard. */
printf("Enter distance in meters: \n");
scanf("%lf",&dist_meter);

/* Convert meter to miles*/
dist_mile = dist_meter * 0.000621371;
printf("\n%lf meters is equivalent to %lf miles\n", dist_meter, dist_mile);

/* Exit program. */
return 0;
}
/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/

Convert Celsius to Rankine

#include <stdio.h>
#include <math.h>
int main(void)
{

/* Declare and initialize variables. */
double celsius, fahrenheit, rankine;

/* Get user input from the keyboard. */
printf("Enter temperature in Celsius: \n");
scanf("%lf",&celsius);

/* Convert celsius to rankine*/
fahrenheit = celsius * 9/5 + 32;
rankine = fahrenheit + 459.67;
printf("\n%lf Celsius is equivalent to %lf Rankine \n", celsius, rankine);

/* Exit program. */
return 0;
}
/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/

Area of a Ellipse
#include <stdio.h>
#include <math.h>
int main(void)
{
/* Declare and initialize variables. */
double semi_major, semi_minor, area_ellipse;

#define PI 3.141593
/* Get user input from the keyboard. */
printf("Enter values in meters to calculate area of an ellipse.\n");
printf("\nEnter length of semiaxis a: \n");
scanf("%lf",&semi_major);
printf("Enter length of semiaxis b: \n");
scanf("%lf", &semi_minor);

/* Compute area of ellipse*/
area_ellipse = PI * semi_major * semi_minor;
printf("\nThe area of the ellipse is %lf meters squared\n", area_ellipse);
/* Exit program. */
return 0;
}
/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/

Area of a Sector of a Cirle

#include <stdio.h>
#include <math.h>
int main(void)
{

/* Declare and initialize variables. */
double angle_sector, radius, area_sector;
#define PI 3.141593

/* Get user input from the keyboard. */
printf("Enter value in meters to calculate area of a sector.\n");
printf("Enter length of radius of your circle: \n");
scanf("%lf",&radius);
printf("\nEnter value in degrees for angle of a sector.\n");
printf("Enter angle of your sector: \n");
scanf("%lf", &angle_sector);

/* Compute area of sector*/
area_sector = (angle_sector / 360) * (PI * radius * radius);
printf("\nThe area of the sector is %lf meters squared.\n", area_sector);

/* Exit program. */
return 0;
}
/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/