Started Homework 3
++ Fibonacci ++ Jump the Five ++ Temperature Chart
This commit is contained in:
parent
e68af45401
commit
aae5754baa
4 changed files with 135 additions and 0 deletions
BIN
Homework3/fibonacci
Executable file
BIN
Homework3/fibonacci
Executable file
Binary file not shown.
56
Homework3/fibonacci.c
Normal file
56
Homework3/fibonacci.c
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
// header files
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
// local constants
|
||||||
|
|
||||||
|
/*
|
||||||
|
Name: Fibonacci Sequence
|
||||||
|
Process: Accepts single integer, prints out up to nth term of the sequence.
|
||||||
|
Function input/parameters: argc and argv command line arguments
|
||||||
|
Function output/parameters: NONE
|
||||||
|
Function output/returned: NONE
|
||||||
|
Device input/---: NONE
|
||||||
|
Device output/---: NONE
|
||||||
|
Dependencies: included by standard libraries
|
||||||
|
*/
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
// define local variables
|
||||||
|
int fibonacciNumber = 0;
|
||||||
|
int prevFibonacciNumber, prevPrevFibonacciNumber;
|
||||||
|
int fibN1 = 0, fibN2 = 1;
|
||||||
|
int nthTerm = atoi(argv[1]);
|
||||||
|
int counter;
|
||||||
|
// do calculations
|
||||||
|
if(argc == 2 && nthTerm >= 0)
|
||||||
|
{
|
||||||
|
// check to see if the correct number of arguments are included
|
||||||
|
// fibonacci sequence loop until n.
|
||||||
|
fibonacciNumber = fibN1 + fibN2;
|
||||||
|
prevFibonacciNumber = fibonacciNumber;
|
||||||
|
fibonacciNumber = fibN2 + prevFibonacciNumber;
|
||||||
|
prevPrevFibonacciNumber = prevFibonacciNumber;
|
||||||
|
prevFibonacciNumber = fibonacciNumber;
|
||||||
|
for(counter = 0; counter < nthTerm - 2; counter++)
|
||||||
|
{
|
||||||
|
// get the next fibonacci number
|
||||||
|
fibonacciNumber = prevPrevFibonacciNumber + prevFibonacciNumber;
|
||||||
|
prevPrevFibonacciNumber = prevFibonacciNumber;
|
||||||
|
prevFibonacciNumber = fibonacciNumber;
|
||||||
|
}
|
||||||
|
printf("The %dth term of the Fibonacci Sequence is: %d\n", nthTerm, prevPrevFibonacciNumber);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// fail program
|
||||||
|
printf("Please provide one integer greater than zero.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
// display results
|
||||||
|
// done in do calculations
|
||||||
|
// return success
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
26
Homework3/jump_the_five.c
Normal file
26
Homework3/jump_the_five.c
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
// header files
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
// local constants
|
||||||
|
|
||||||
|
/*
|
||||||
|
Name: Jump the Five
|
||||||
|
Process: Takes in 7 or 10 numbers, and applies a transformation to the numbers.
|
||||||
|
Function input/parameters: argc and argv command line parameters
|
||||||
|
Function output/parameters: NONE
|
||||||
|
Function output/returned: NONE
|
||||||
|
Device input/---: NONE
|
||||||
|
Device output/---: NONE
|
||||||
|
Dependencies: included by standard libraries
|
||||||
|
*/
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
// define local variables
|
||||||
|
// do calculations
|
||||||
|
// display results
|
||||||
|
// return success
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
53
Homework3/temperature_chart.c
Normal file
53
Homework3/temperature_chart.c
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
// header files
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
// local constants
|
||||||
|
|
||||||
|
/*
|
||||||
|
Name: Temperature Chart
|
||||||
|
Process: Accepts up to three numbers and prints out the Fahrenheit and Celcius
|
||||||
|
degrees between the two numbers, with an optional step as third number.
|
||||||
|
Function input/parameters: argc and argv command line parameters
|
||||||
|
Function output/parameters: NONE
|
||||||
|
Function output/returned: NONE
|
||||||
|
Device input/---: NONE
|
||||||
|
Device output/---: NONE
|
||||||
|
Dependencies: included by standard libraries
|
||||||
|
*/
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
// define local variables
|
||||||
|
double start = atof(argv[1]), stop = atof(argv[2]);
|
||||||
|
int step = 1;
|
||||||
|
int tempIterator;
|
||||||
|
// do calculations
|
||||||
|
if(argc == 3 || argc == 2)
|
||||||
|
{
|
||||||
|
// do the temperature chart stuff here
|
||||||
|
// check to see if a step is provided
|
||||||
|
if(argc == 3)
|
||||||
|
{
|
||||||
|
step = atof(argv[3]);
|
||||||
|
}
|
||||||
|
// do the printing and looping
|
||||||
|
printf("%f\t%f\n", start, start);
|
||||||
|
for(tempIterator = 0; tempIterator < stop; tempIterator++)
|
||||||
|
{
|
||||||
|
// print out the temp and it's conversion
|
||||||
|
printf("%f\t%f\n", );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// fail program
|
||||||
|
printf("Please provide two or three integers.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
// display results
|
||||||
|
// done in do calculations
|
||||||
|
// return success
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue