Added all previous files
This commit is contained in:
parent
4466ee8a4c
commit
f04fb2189a
59 changed files with 64921 additions and 0 deletions
31
lab1/prog1.c
Normal file
31
lab1/prog1.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
// Owen Dorweiler
|
||||
// Fundamentals of Computing
|
||||
// Lab 1, Football Score Formula
|
||||
// Calculates final team score from user inputs
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
// Initialize variables
|
||||
int touchdowns, extraPoints, fieldGoals, safeties;
|
||||
int total;
|
||||
|
||||
// Get inputs
|
||||
printf("Enter number of touchdowns: ");
|
||||
scanf("%d", &touchdowns);
|
||||
|
||||
printf("Enter number of extra points: ");
|
||||
scanf("%d", &extraPoints);
|
||||
|
||||
printf("Enter number of field goals: ");
|
||||
scanf("%d", &fieldGoals);
|
||||
|
||||
printf("Enter number of safeties: ");
|
||||
scanf("%d", &safeties);
|
||||
|
||||
// Calculate total
|
||||
total = (touchdowns*6) + (extraPoints*1) + (fieldGoals*3) + (safeties*2);
|
||||
|
||||
// Display total
|
||||
printf("Total points scored: %d\n", total);
|
||||
}
|
||||
42
lab1/prog2.c
Normal file
42
lab1/prog2.c
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
// Owen Dorweiler
|
||||
// Fundamentals of Computing
|
||||
// Lab 1, Formula Calculator
|
||||
// Calculates zeros using the quadratic formula given a, b, c inputs
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
int main () {
|
||||
// Initialize variables
|
||||
double a, b, c;
|
||||
double disc;
|
||||
double zero1, zero2;
|
||||
|
||||
//Print title
|
||||
printf("Quadratic Formula Calculator\n");
|
||||
|
||||
// Get inputs
|
||||
printf("Enter A: ");
|
||||
scanf("%lf", &a);
|
||||
|
||||
printf("Enter B: ");
|
||||
scanf("%lf", &b);
|
||||
|
||||
printf("Enter C: ");
|
||||
scanf("%lf", &c);
|
||||
|
||||
// Calculate discriminant
|
||||
disc = (b*b) - (4*a*c);
|
||||
|
||||
if (disc > 0) {
|
||||
// Calculate zeros
|
||||
zero1 = (-b + sqrt(disc)) / (2*a);
|
||||
zero2 = (-b - sqrt(disc)) / (2*a);
|
||||
|
||||
// Print result
|
||||
printf("The first zero is %.4lf\n", zero1);
|
||||
printf("The second zero is: %.4lf\n", zero2);
|
||||
}
|
||||
// Print error message if discriminant is not greater than 0
|
||||
else printf("Result does not yield two real and distinct zeros. Try again.\n");
|
||||
}
|
||||
9
lab1/report.txt
Normal file
9
lab1/report.txt
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
Lab Report
|
||||
Owen Dorweiler
|
||||
Fundamentals of Computing, Lab 1
|
||||
|
||||
My program in part 2 is meant to find the zeros of an quadratic equation using the quadratic formula.
|
||||
|
||||
The program first declares the variables for a, b, and c, followed by the discriminant variables and finally the zero variables. It then accepts user inputs for a, b, and c, and calculates the discriminant. If the discriminant is greater than 0, it calculates the zeros and prints the solution to 4 decimal places. Otherwise, it prints an error message since the zeros are not disctinct and may not be real.
|
||||
|
||||
I have verified that the program produces correct responses by running all the edge cases through it and comparing with a quadratic formula solver online. It correctly identifies the zeros when it can, and displays the error message correctly as well. I did not find any situation where it gave an incorrect output.
|
||||
Loading…
Reference in a new issue