#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978
#define melodyPin 8
//Mario main theme melody
int melody[] = {
NOTE_E7, NOTE_E7, 0, NOTE_E7,
0, NOTE_C7, NOTE_E7, 0,
NOTE_G7, 0, 0, 0,
NOTE_G6, 0, 0, 0,
NOTE_C7, 0, 0, NOTE_G6,
0, 0, NOTE_E6, 0,
0, NOTE_A6, 0, NOTE_B6,
0, NOTE_AS6, NOTE_A6, 0,
NOTE_G6, NOTE_E7, NOTE_G7,
NOTE_A7, 0, NOTE_F7, NOTE_G7,
0, NOTE_E7, 0, NOTE_C7,
NOTE_D7, NOTE_B6, 0, 0,
NOTE_C7, 0, 0, NOTE_G6,
0, 0, NOTE_E6, 0,
0, NOTE_A6, 0, NOTE_B6,
0, NOTE_AS6, NOTE_A6, 0,
NOTE_G6, NOTE_E7, NOTE_G7,
NOTE_A7, 0, NOTE_F7, NOTE_G7,
0, NOTE_E7, 0, NOTE_C7,
NOTE_D7, NOTE_B6, 0, 0
};
//Mario main them tempo
int tempo[] = {
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
9, 9, 9,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
9, 9, 9,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
};
//Underworld melody
int underworld_melody[] = {
NOTE_C4, NOTE_C5, NOTE_A3, NOTE_A4,
NOTE_AS3, NOTE_AS4, 0,
0,
NOTE_C4, NOTE_C5, NOTE_A3, NOTE_A4,
NOTE_AS3, NOTE_AS4, 0,
0,
NOTE_F3, NOTE_F4, NOTE_D3, NOTE_D4,
NOTE_DS3, NOTE_DS4, 0,
0,
NOTE_F3, NOTE_F4, NOTE_D3, NOTE_D4,
NOTE_DS3, NOTE_DS4, 0,
0, NOTE_DS4, NOTE_CS4, NOTE_D4,
NOTE_CS4, NOTE_DS4,
NOTE_DS4, NOTE_GS3,
NOTE_G3, NOTE_CS4,
NOTE_C4, NOTE_FS4, NOTE_F4, NOTE_E3, NOTE_AS4, NOTE_A4,
NOTE_GS4, NOTE_DS4, NOTE_B3,
NOTE_AS3, NOTE_A3, NOTE_GS3,
0, 0, 0
};
//Underwolrd tempo
int underworld_tempo[] = {
12, 12, 12, 12,
12, 12, 6,
3,
12, 12, 12, 12,
12, 12, 6,
3,
12, 12, 12, 12,
12, 12, 6,
3,
12, 12, 12, 12,
12, 12, 6,
6, 18, 18, 18,
6, 6,
6, 6,
6, 6,
18, 18, 18, 18, 18, 18,
10, 10, 10,
10, 10, 10,
3, 3, 3
};
void setup(void)
{
pinMode(8, OUTPUT);//buzzer
pinMode(10, OUTPUT);//led indicator when singing a note
}
void loop()
{
//sing the tunes
sing(1);
sing(1);
sing(2);
}
int song = 0;
void sing(int s) {
// iterate over the notes of the melody:
song = s;
if (song == 2) {
Serial.println(" 'Underworld Theme'");
int size = sizeof(underworld_melody) / sizeof(int);
for (int thisNote = 0; thisNote < size; thisNote++) {
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000 / underworld_tempo[thisNote];
buzz(melodyPin, underworld_melody[thisNote], noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
buzz(melodyPin, 0, noteDuration);
}
} else {
Serial.println(" 'Mario Theme'");
int size = sizeof(melody) / sizeof(int);
for (int thisNote = 0; thisNote < size; thisNote++) {
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000 / tempo[thisNote];
buzz(melodyPin, melody[thisNote], noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
buzz(melodyPin, 0, noteDuration);
}
}
}
void buzz(int targetPin, long frequency, long length) {
digitalWrite(10, HIGH);
long delayValue = 1000000 / frequency / 2; // calculate the delay value between transitions
//// 1 second's worth of microseconds, divided by the frequency, then split in half since
//// there are two phases to each cycle
long numCycles = frequency * length / 1000; // calculate the number of cycles for proper timing
//// multiply frequency, which is really cycles per second, by the number of seconds to
//// get the total number of cycles to produce
for (long i = 0; i < numCycles; i++) { // for the calculated length of time...
digitalWrite(targetPin, HIGH); // write the buzzer pin high to push out the diaphram
delayMicroseconds(delayValue); // wait for the calculated delay value
digitalWrite(targetPin, LOW); // write the buzzer pin low to pull back the diaphram
delayMicroseconds(delayValue); // wait again or the calculated delay value
}
digitalWrite(10, LOW);
}
Thursday, September 20, 2018
Tuesday, September 18, 2018
day 6 lab
const int LED=9; //Red LED on pin 9 (PWM)
const int LIGHT=0; //Lght Sensor on analog pin 0
const int MIN_LIGHT=200; //Minimum expected light value
const int MAX_LIGHT=900; //Maximum Expected Light value
const int PIR=2;//The PIR is connected to pin 2
const int max_thresh = 10; // Maximum threshold
int val = 0; //variable to hold the analog reading
void setup()
{
pinMode(LED, OUTPUT); //Set LED pin as output
pinMode (PIR, INPUT);
Serial.begin(9600); //Start Serial Communication
}
void loop()
{
val = analogRead(LIGHT); //Read the light sensor
val = map(val, MIN_LIGHT, MAX_LIGHT, 255, 0);//Map the light reading
val = constrain(val, 0, 255); //Constrain light value
Serial.println(val); //Print it to the serial port
delay(500);
int PIRcount = digitalRead(PIR);
if (digitalRead(PIR) == LOW && val == 255)
{
if( PIRcount < max_thresh);
{
digitalWrite(LED,HIGH); //Set the LED On
delay(400); //Wait for 100 ms
digitalWrite(LED,LOW); //Set the LED Off
delay(80); //Wait for 10 second
PIRcount++;
}
}
else if(digitalRead(PIR) == HIGH)
{
digitalWrite(LED,HIGH); //Set the LED on
}
else if (digitalRead(PIR) == LOW && val <= 96)
{
digitalWrite(LED,LOW); //Set the LED off
}
}
const int LIGHT=0; //Lght Sensor on analog pin 0
const int MIN_LIGHT=200; //Minimum expected light value
const int MAX_LIGHT=900; //Maximum Expected Light value
const int PIR=2;//The PIR is connected to pin 2
const int max_thresh = 10; // Maximum threshold
int val = 0; //variable to hold the analog reading
void setup()
{
pinMode(LED, OUTPUT); //Set LED pin as output
pinMode (PIR, INPUT);
Serial.begin(9600); //Start Serial Communication
}
void loop()
{
val = analogRead(LIGHT); //Read the light sensor
val = map(val, MIN_LIGHT, MAX_LIGHT, 255, 0);//Map the light reading
val = constrain(val, 0, 255); //Constrain light value
Serial.println(val); //Print it to the serial port
delay(500);
int PIRcount = digitalRead(PIR);
if (digitalRead(PIR) == LOW && val == 255)
{
if( PIRcount < max_thresh);
{
digitalWrite(LED,HIGH); //Set the LED On
delay(400); //Wait for 100 ms
digitalWrite(LED,LOW); //Set the LED Off
delay(80); //Wait for 10 second
PIRcount++;
}
}
else if(digitalRead(PIR) == HIGH)
{
digitalWrite(LED,HIGH); //Set the LED on
}
else if (digitalRead(PIR) == LOW && val <= 96)
{
digitalWrite(LED,LOW); //Set the LED off
}
}
day 6 assignment
/* 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;
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;
}
//////////////////////////////////////////////
/* This function computes the distance between two */
/* points using great circle distances. */
double gc_distance(double lat1,double long1,
double lat2,double long2)
{
/* Declare variables. */
double rho, phi, theta, gamma, dot, dist1, dist2,x1, y1, z1, x2, y2, z2;
/* Convert latitude,longitude to rectangular coordinates. */
rho = 3960;
phi = (90 - lat1)*(PI/180.0);
theta = (360 - long1)*(PI/180.0);
x1 = rho*sin(phi)*cos(theta);
y1 = rho*sin(phi)*sin(theta);
z1 = rho*cos(phi);
phi = (90 - lat2)*(PI/180.0);
theta = (360 - long2)*(PI/180.0);
x2 = rho*sin(phi)*cos(theta);
y2 = rho*sin(phi)*sin(theta);
z2 = rho*cos(phi);
/* Compute angle between vectors. */
dot = x1*x2 + y1*y2 + z1*z2;
dist1 = sqrt(x1*x1 + y1*y1 + z1*z1);
dist2 = sqrt(x2*x2 + y2*y2 + z2*z2);
gamma = acos(dot/(dist1*dist2));
/* Compute and return great circle distance. */
return gamma*rho;
}
Wednesday, September 12, 2018
day 5 assigment
#include <stdio.h>
#include <math.h>
int main(void)
{
/*Declare variables.*/
double x, t_a, t_b, a, b, f_a, f_b, t_c, f_1, f_2,
t, steps, max, sum, ti, ws1, ws2, Pi= 3.14159, min;
/* User input.*/
printf("Use seconds for period. \n");
printf("Use feet for wave height. \n");
printf("Enter period and wave height for wave 1. \n");
scanf("%lf %lf", &t_a, &a);
printf("Enter period and wave height for wave. \n");
scanf("%lf %lf", &t_b, &b);
printf("Enter desired time. \n");
scanf("%lf", &x);
//* Use given equation to compute wavelength 1
f_a = 5.13*(t_a*t_a);
//* Use given equation to compute wavelength 2
f_b = 5.13*(t_b*t_b);
/* Print Wavelength 1. */
printf("Wavelength 1 in ft: %4.2f \n", f_a);
/* Print Wavelength 2. */
printf("Wavelength 2 in ft: %4.2f \n", f_b);
t_c = t_a*t_b;
ti = t_c/200;
max = 0;
ti = 0;
f_1 = 1/t_a;
f_2 = 1/t_b;
steps = 0;
while (steps <= 199){
t = (steps*x);
ws1 = (0.5 * a)*(sin(2 * Pi * f_1 * t));
ws2 = (0.5 * b)*(sin(2 * Pi * f_2 * t));
sum = ws1 + ws2;
if (sum > max)
max = sum;
if (sum < min)
min = sum;
steps++;}
printf("Wavemax in ft: %4.2f \n",max*2);
printf("maximum crest in ft: %4.2f \n", max);
printf("minimum trough in ft: %4.2f \n", min);
return 0;
}
Tuesday, September 11, 2018
day 5 lab
//Potentiometer Reading Program
const int POT=0; //Pot on analog pin 0
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);
}
//Temperature Reading LED program
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 POT=0; //Pot on analog pin 0
int val = 0; //variable to hold the analog reading from the POT
void setup()
{
Serial.begin(9600); //Start Serial Communication
}
void loop()
{
double mV= val*5, temp= abs(mV - 500)/10;
val = analogRead(POT); //Read one value from the POT
Serial.println("degrees C:" );
Serial.println(temp); //Print it to the serial port
delay(500);
if (val<138)
{
digitalWrite(RLED, LOW);
digitalWrite(GLED, LOW);
digitalWrite(BLED, HIGH);
}
else if (val>148)
{
digitalWrite(RLED, HIGH);
digitalWrite(GLED, LOW);
digitalWrite(BLED, LOW);
}
else if(val=143)
{
digitalWrite(RLED, LOW);
digitalWrite(GLED, HIGH);
digitalWrite(BLED, LOW);
}
delay(1);
return;}
const int POT=0; //Pot on analog pin 0
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);
}
//Temperature Reading LED program
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 POT=0; //Pot on analog pin 0
int val = 0; //variable to hold the analog reading from the POT
void setup()
{
Serial.begin(9600); //Start Serial Communication
}
void loop()
{
double mV= val*5, temp= abs(mV - 500)/10;
val = analogRead(POT); //Read one value from the POT
Serial.println("degrees C:" );
Serial.println(temp); //Print it to the serial port
delay(500);
if (val<138)
{
digitalWrite(RLED, LOW);
digitalWrite(GLED, LOW);
digitalWrite(BLED, HIGH);
}
else if (val>148)
{
digitalWrite(RLED, HIGH);
digitalWrite(GLED, LOW);
digitalWrite(BLED, LOW);
}
else if(val=143)
{
digitalWrite(RLED, LOW);
digitalWrite(GLED, HIGH);
digitalWrite(BLED, LOW);
}
delay(1);
return;}
Day 4 Assigntment
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 BUTTON=2; //The Button is connected to pin 2
boolean lastButton = LOW; //Last Button State
boolean currentButton = LOW; //Current Button State
const int BUTTON2=3; //The Button is connected to pin 2
boolean lastButton1 = LOW; //Last Button State
boolean currentButton1 = LOW; //Current Button State
const int BUTTON3=4; //The Button is connected to pin 2
boolean lastButton2 = LOW; //Last Button State
boolean currentButton2 = LOW; //Current Button State
const int BUTTON4=5; //The Button is connected to pin 2
boolean lastButton3 = LOW; //Last Button State
boolean currentButton3 = LOW; //Current Button State
int ledMode = 0; //Cycle between LED states
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 (BUTTON, INPUT); //Set button as input
pinMode (BUTTON2, INPUT); //Set button as input
pinMode (BUTTON3, INPUT); //Set button as input
pinMode (BUTTON4, INPUT); //Set button as input
}
boolean debounce(boolean last)
{
boolean current = digitalRead(BUTTON); //Read the button state
if (last != current) //if it's different...
{
delay(5); //wait 5ms
current = digitalRead(BUTTON); //read it again
}
return current; //return the current value
}
boolean debounce1(boolean Last)
{
boolean current1 = digitalRead(BUTTON2); //Read the button state
if (Last != current1) //if it's different...
{
delay(5); //wait 5ms
current1 = digitalRead(BUTTON2); //read it again
}
return current1; //return the current value
}
boolean debounce2(boolean Last1)
{
boolean current2 = digitalRead(BUTTON3); //Read the button state
if (Last1 != current2) //if it's different...
{
delay(5); //wait 5ms
current2 = digitalRead(BUTTON3); //read it again
}
return current2; //return the current value
}
boolean debounce3(boolean Last2)
{
boolean current3 = digitalRead(BUTTON4); //Read the button state
if (Last2 != current3) //if it's different...
{
delay(5); //wait 5ms
current3 = digitalRead(BUTTON4); //read it again
}
return current3; //return the current value
}
/*
* LED Mode Selection Pass a number for the LED state and set it accordingly.
*/
void setMode(int button)
{
switch (button)
{
//teal
case 1:
analogWrite(RLED, 0);
analogWrite(GLED, 128);
analogWrite(BLED, 128);
break;
//orange
case 2:
analogWrite(RLED, 255);
analogWrite(GLED, 165);
analogWrite(BLED, 0);
break;
//white
case 3:
analogWrite(RLED, 255);
analogWrite(GLED, 255);
analogWrite(BLED, 255);
break;
//OFF (mode = 0)
default:
analogWrite(RLED, 0);
analogWrite(GLED, 0);
analogWrite(BLED, 0);
}
}
void loop()
{
currentButton = debounce(lastButton); //read debounced state
if (lastButton == LOW && currentButton == HIGH) //if it was pressed...
{
ledMode++; //increment the LED value
}
lastButton = currentButton; //reset button value
if (ledMode == 1) ledMode = 0;
setMode(ledMode); //change the LED state
currentButton1 = debounce1(lastButton1); //read debounced state
if (lastButton1 == LOW && currentButton1 == HIGH) //if it was pressed...
{
ledMode++; //increment the LED value
}
lastButton1 = currentButton1; //reset button value
//if you've cycled through the different options,
//reset the counter to 0
if (ledMode == 2) ledMode = 0;
setMode(ledMode); //change the LED state
currentButton2 = debounce2(lastButton2); //read debounced state
if (lastButton2 == LOW && currentButton2 == HIGH) //if it was pressed...
{
ledMode++; //increment the LED value
}
lastButton2 = currentButton2; //reset button value
//if you've cycled through the different options,
//reset the counter to 0
if (ledMode == 3) ledMode = 0;
setMode(ledMode); //change the LED state
currentButton3 = debounce3(lastButton3); //read debounced state
if (lastButton3 == LOW && currentButton3 == HIGH) //if it was pressed...
{
ledMode++; //increment the LED value
}
lastButton3 = currentButton3; //reset button value
//if you've cycled through the different options,
//reset the counter to 0
if (ledMode == 4) ledMode = 0;
setMode(ledMode); //change the LED state
}
Thursday, September 6, 2018
Day3 Lab
const int LED=9; //The LED is connected to pin 9
const int BUTTON=2; //The Button is connected to pin 2
const int LED2=10; //The LED is connected to pin 10
const int BUTTON2=4; //The Button is connected to pin 3
boolean lastButton = LOW; //Variable containing the previous button state
boolean currentButton = LOW; //Variable containing the current button state
boolean ledOn = false; //The present state of the LED (on/off)
boolean lastButton2 = LOW; //Variable containing the previous button state
boolean currentButton2 = LOW; //Variable containing the current button state
boolean led2On = false; //The present state of the LED (on/off)
void setup()
{
pinMode (LED, OUTPUT); //Set the LED pin as an output
pinMode (BUTTON, INPUT); //Set button as input (not required)
pinMode (LED2, OUTPUT); //Set the LED2 pin as an output
pinMode (BUTTON2, INPUT); //Set button2 as input (not required)
}
/*
* Debouncing Function Pass it the previous button state,
* and get back the current debounced button state.
*/
boolean debounce(boolean last)
{
boolean current = digitalRead(BUTTON);
if (last != current) //if it's different…
{
delay(5); //wait 5ms
current = digitalRead(BUTTON); //read it again
return current; //return the current value
}
}
boolean deboucnce(boolean Last)
{
boolean current2 = digitalRead(BUTTON2);//Read the button2 state
if (Last != current2) //if it's different…
{
delay(5); // wait 5ms
current2 = digitalRead(BUTTON2); //read it again
return current2; //return the current value
}
}
void loop()
{
currentButton = debounce(lastButton); //read debounced state
if (lastButton == LOW && currentButton == HIGH) //if it was pressed...
{
ledOn = !ledOn; //toggle the LED value
}
lastButton = currentButton; //reset button value
digitalWrite(LED, ledOn); //change the LED state
{
currentButton2 = debounce(lastButton2); //read debounced state
if (lastButton2 == LOW && currentButton2 == HIGH) //if it was pressed...
{
led2On =!led2On; // toggle the LED2 value
}
lastButton2 = currentButton2; //reset button value
digitalWrite(LED2, led2On); //change the LED state
}
}
Wednesday, September 5, 2018
Day 3 Assignment
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
/* 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, t_c;
/* 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);
// Use value of new freezing temperature to convert into Centigrade.
t_c = (5*f_b/9) - 32;
/* Print new freezing temperature. */
printf("New freezing temperature in degrees C: %4.1f \n",t_c);
return 0; /* Exit program. */
}
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
Subscribe to:
Comments (Atom)