mirror of
https://github.com/caperren/school_archives.git
synced 2025-11-10 06:01:13 +00:00
Added files from first programming course at OSU
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Original Author: Corwin A. Perren (perrenc)
|
||||
* File: perrenc_hw0_1.c
|
||||
* Created: Unknown by perrenc
|
||||
* Last Modified: 2012 February 21,20:33 by perrenc
|
||||
*
|
||||
* Prints out integers and decimals with specific numbers of decimal points.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
|
||||
/*
|
||||
* Creates integers and float variables, then assigns a computed value to them
|
||||
*/
|
||||
int a = (2 * 3);
|
||||
int b = (1 / 5);
|
||||
int c = (1 / 2);
|
||||
int d = (3 / 2);
|
||||
int e = (1 / 3);
|
||||
int f = (2 / 3);
|
||||
double g = (1.0 / 5);
|
||||
double h = (1.0 / 2);
|
||||
double i = (3.0 / 2);
|
||||
double j = (1.0 / 3);
|
||||
double k = (2.0 / 3);
|
||||
double l = (1 / 5.0);
|
||||
double m = (1 / 2.0);
|
||||
double n = (3 / 2.0);
|
||||
double o = (1 / 3.0);
|
||||
double p = (2 / 3.0);
|
||||
|
||||
/*
|
||||
* Prints the integers with no decimal points and then prints the float values
|
||||
* with 6 and 20 decimal points
|
||||
*/
|
||||
printf("a = %i\n", a);
|
||||
printf("b = %i\n", b);
|
||||
printf("c = %i\n", c);
|
||||
printf("d = %i\n", d);
|
||||
printf("e = %i\n", e);
|
||||
printf("f = %i\n", f);
|
||||
printf("g = %.06f\n %.20f\n", g, g);
|
||||
printf("h = %.06f\n %.20f\n", h, h);
|
||||
printf("i = %.06f\n %.20f\n", i, i);
|
||||
printf("j = %.06f\n %.20f\n", j, j);
|
||||
printf("k = %.06f\n %.20f\n", k, k);
|
||||
printf("l = %.06f\n %.20f\n", l, l);
|
||||
printf("m = %.06f\n %.20f\n", m, m);
|
||||
printf("n = %.06f\n %.20f\n", n, n);
|
||||
printf("o = %.06f\n %.20f\n", o, o);
|
||||
printf("p = %.06f\n %.20f\n", p, p);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Original Author: Corwin A. Perren (perrenc)
|
||||
* File: perrenc_hw0_2.c
|
||||
* Created: Unknown by perrenc
|
||||
* Last Modified: 2012 February 21, 20:36 by perrenc
|
||||
*
|
||||
* Uses printf to print integers the same way through two different methods.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
|
||||
/*
|
||||
* Creates variables for holding integers between and including 1 to 4 assigns
|
||||
* one of these values to each variable.
|
||||
*/
|
||||
int a = 1;
|
||||
int b = 2;
|
||||
int c = 3;
|
||||
int d = 4;
|
||||
|
||||
/* Prints the four integer values on one line using a single printf statement. */
|
||||
printf("%d, %d, %d, %d\n\n", a, b, c, d);
|
||||
|
||||
/*
|
||||
* Prints the four integer values on the same line using four different printf
|
||||
* statements.
|
||||
*/
|
||||
printf("%d, ", a);
|
||||
printf("%d, ", b);
|
||||
printf("%d, ", c);
|
||||
printf("%d\n", d);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Original Author: Corwin A. Perren (perrenc)
|
||||
* File: perrenc_hw0_4.c
|
||||
* Created: Unknown by perrenc
|
||||
* Last Modified: 2012 February 21, 20:41 by perrenc
|
||||
*
|
||||
* Prints out integers from 10 down by using a for loop and if statement.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
|
||||
/* Creates a variable for manipulation and sets it to an inital value of 10. */
|
||||
int x = 10;
|
||||
|
||||
/*
|
||||
* Takes x and prints its value and a comma from 10 to 2, then when the if
|
||||
* statement falsifies, it prints the final value with a new line and exits.
|
||||
*/
|
||||
for( x ; x >= 1 ; x -= 1) {
|
||||
if (x != 1){
|
||||
printf("%d, ", x);
|
||||
}else{
|
||||
printf("%d\n", x);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Original Author: Corwin A. Perren (perrenc)
|
||||
* File: perrenc_hw0_5.c
|
||||
* Created: Unknown by perrenc
|
||||
* Last Modified: 2012 February 21, 20:49 by perrenc
|
||||
*
|
||||
* Total all integers from 1 to whatever value is necessary to make x in the loop equal
|
||||
* to 1000.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv){
|
||||
|
||||
int x; // Variable used for incrementing
|
||||
int total; // Variable used for holding the total amount
|
||||
|
||||
/* Increments x, then adds current x to the total until x is equal to 1000. */
|
||||
for(x = 1 ; x <= 1000 ; x++){
|
||||
total += x;
|
||||
}
|
||||
|
||||
/* Prints the total after going through the loop. */
|
||||
printf("%d\n", total);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Original Author: Corwin A. Perren (perrenc)
|
||||
* File: perrenc_hw0_6.c
|
||||
* Created: Unknown by perrenc
|
||||
* Last Modified: 2012 February 21, 20:54 by perrenc
|
||||
*
|
||||
* Calulates and prints out the fibonacci sequence up to a value the user specifies.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main (int argc, char **argv){
|
||||
|
||||
int x; // Used for loop limiting
|
||||
int k; // Used for user input
|
||||
int a = 0; // Beginning of the fibonacci sequences
|
||||
int b = 1; // Another beginning value of the fibonacci sequence
|
||||
int total;
|
||||
|
||||
/*
|
||||
* Asks users to what value of the fibonacci sequence they would like to
|
||||
* calculate and then stores it in k
|
||||
*/
|
||||
printf("Enter to what iteration of the fibonacci sequence you want to calculate: ");
|
||||
scanf("%d", &k);
|
||||
|
||||
/*
|
||||
* Prints an iteration of the fibonacci sequence, totals the two previous values
|
||||
* to make the next iteration, then loops until the number of iterations reaches
|
||||
* what the user inputted previously.
|
||||
*/
|
||||
for(x = 0 ; x < k ; x++){
|
||||
printf("%d ", a);
|
||||
total = a + b;
|
||||
a = b;
|
||||
b = total;
|
||||
}
|
||||
|
||||
/* Prints a new line to make the output cleaner. */
|
||||
printf("\n");
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Original Author: Corwin A. Perren (perrenc)
|
||||
* File: perrenc_hw0_7.c
|
||||
* Created: Unknown by perrenc
|
||||
* Last Modified: 2012 February 21, 20:54 by perrenc
|
||||
*
|
||||
* Prints the ascii character for the number a user enters.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv){
|
||||
|
||||
int x; // Variable used for user input
|
||||
|
||||
/* Ask user for input, then store it on x. */
|
||||
printf("Please enter a number between 0 and 255: ");
|
||||
scanf("%d", &x);
|
||||
|
||||
/* Prints the appropriate ascii character for an entered value as long as it is
|
||||
* within range, else it prints an error, or exits with a "-1" input.
|
||||
*/
|
||||
if ((x < 0 | x > 255) & (x != -1)){
|
||||
printf("You entered an improper value or it was out of range...\n");
|
||||
}else if ((x >= 0) & (x <= 255)){
|
||||
printf("%c\n", x);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Original Author: Corwin A. Perren (perrenc)
|
||||
* File: perrenc_hw0_9.c
|
||||
* Created: Unknown by perrenc
|
||||
* Last Modified: 2012 February 21, 20:54 by perrenc
|
||||
*
|
||||
* Print the square and cube roots of values from 1 to 25.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
int main(int argc, char **argv){
|
||||
|
||||
int x; // Variable used for incrementing from 1 to 25
|
||||
double y; // Variable used for squares and cubes manipulation
|
||||
|
||||
/*
|
||||
* Increments x from 1 to 25 and prints the x value, its square root, and cube
|
||||
* root in column format, then ends.
|
||||
*/
|
||||
for(x = 1 ; x <= 25 ; x++){
|
||||
y = x;
|
||||
printf("%i ", x);
|
||||
y = sqrt (x); // Takes the square root of x
|
||||
printf("%f ", y);
|
||||
y = pow(x, (1/3.0)); // Takes the cube root of x
|
||||
printf("%f \n", y);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user