├── ArrayStudy.c ├── Assignment10.c ├── HW8inProgress.c ├── LICENSE ├── Quiz 6.c ├── README.md ├── Switch (2)fromwill.c ├── Switch.c ├── SwitchlowNumOnly.c ├── alternative method to switch using if else ├── arithmicoperations.c ├── arrayHW 9 in progress.c ├── arrayINclassGrade.c ├── assignment1.c ├── assignment2.c ├── assignment2revised.c ├── assignment7.c ├── assignment_7.c ├── checkpoint4_mpg.c ├── convertTemps.c ├── determining perfect number ├── determining perfect number using functions ├── differentiation prog ├── digital clock creator ├── digital clock creator using c ├── example1.c ├── exampleCounterN.c ├── factorials_checkpoint4.c ├── final.c ├── findavegrades2.c ├── functions.c ├── funtions.c ├── games_using_c.c ├── gradesArray.c ├── gradesforclass.c ├── gradesforclassavg.c ├── helloworld.c ├── homework10roughdraft.c ├── homework8.c ├── hw10.c ├── hw10inProgress.c ├── hw5.c ├── hw5avgTestgrades.c ├── hw5inclass.c ├── hw5inclassSample.c ├── hw6_partA.c ├── hw6_partB.c ├── hw6_partC.c ├── hw6_partC_final.c ├── hw6_partD.c ├── hw9.c ├── hw9FINAL.c ├── hw9final.c ├── inclass.c ├── input.c ├── logicalOperators.c ├── nested_for_loops.c ├── numbers.c ├── operators.c ├── periIncheslenghtsquare.c ├── piggybank.c ├── practiceOCT25.c ├── practiceProblem1.c ├── printAVGdiff4numbers.c ├── printAVGof4numbers.c ├── problem3Function.c ├── radiusandcircumfrence.c ├── revisedhwdivisible.c ├── sample 1 hw in class.c ├── shipping.c ├── shortcutOperators.c ├── slide10_7Problems.c ├── structures.c ├── switchpractice.c ├── temp_conversion.c ├── test.c ├── test1.c ├── testGradeScores.c ├── threeprices.c ├── updateArrayStudy.c ├── whileCountMultiples.c ├── while_loops.c ├── whileloops2.c └── whileloops3.c /ArrayStudy.c: -------------------------------------------------------------------------------- 1 | /*Programmer:Chase Singhofen 2 | Date: 3 | Specification:Array's Introduction 4 | */ 5 | 6 | //preprocessors 7 | #include 8 | #include 9 | #define SIZE 20//defined contant. 10 | //main function 11 | main() { 12 | //indexes of an array start with 0. 13 | //int grade1, grade2, grade3 ect.... DON'T USE THIS IN ARRAY!!!!!!!!!!!!!!!!!!!!!!!!! 14 | //declared an ARRAY of int variables that has 10 elements in it 15 | int grades[10] = { 87, 65, 98, 45 };//initializer are whats in brackets. 16 | int i; 17 | double rainfall[SIZE];//size is not a variable its an identifier. subs from define (constant). 18 | grades[0] = 100; 19 | 20 | printf("the first element is %i\n", grades[0]);// 21 | //loop to each element. 22 | for (i = 0; i < 10; i++) {//uses loop for control variable to go thru each element of arry 23 | //goes thu zero thru one less than given number. 24 | printf("element %i has %i \n", i, grades[i]);//%i not the variables. they are used each time through the loop 25 | } 26 | 27 | for (i = 0; i < SIZE; i++) { 28 | 29 | printf("ENTER A RAINFALL AMOUNT: "); 30 | scanf_s("%lf", &rainfall[i]); 31 | printf("rainfall %i has %.2lf\n", i, rainfall[i]); 32 | 33 | } 34 | 35 | 36 | 37 | 38 | 39 | //end main function 40 | system("pause"); 41 | } -------------------------------------------------------------------------------- /Assignment10.c: -------------------------------------------------------------------------------- 1 | /*Programmer: chase 2 | Date: 11/22/2016 3 | Specification: Assignment 10 4 | */ 5 | 6 | //preprocess directives 7 | //standard libraries 8 | #include 9 | #include 10 | 11 | int askNumFahrenheit() {//begin fahrenheit function 12 | 13 | int fahrenheit; 14 | printf("Enter a temperature in Fahrenheit:\n"); 15 | scanf_s("%i", &fahrenheit); 16 | return fahrenheit;//return fahrenheit value 17 | } // ask for the fahrenheit function 18 | 19 | int convFahrenheit(int a) {//conversion function fahrenheit to celsius 20 | 21 | int newcelsius; 22 | newcelsius = (a - 32) / 1.8; 23 | return newcelsius;// returns celsius 24 | } // fahrenheit to celsius conversion 25 | 26 | void printCelsius(int a) {//returns no value 27 | 28 | printf("The converted temperature is %i\xf8 Celsius\n", a); // \xf8 prints degree symbol 29 | 30 | }// print converted Celsius function 31 | 32 | 33 | int askNumCelsius() {// function asking for celsius 34 | 35 | int celsius; 36 | printf("Enter a temperature in Celsius:\n"); 37 | scanf_s("%i", &celsius); 38 | return celsius;//returns celsius value 39 | } // ask for the Celsius function 40 | 41 | int convCelsius(int a) { 42 | 43 | int newFahrenheit; 44 | newFahrenheit = (a * 1.8) + 32; 45 | return newFahrenheit;//function returns farenheit 46 | 47 | } // Celsius to Fahrenheit conversion formula's 48 | 49 | 50 | void printFahrenheit(int a) {//function returns no value 51 | 52 | printf("The converted temperature is %i\xf8 fehrenheit\n", a); 53 | 54 | }// print converted Fahrenheit function 55 | 56 | //main function 57 | main() { 58 | 59 | int choice = 0, num1, num2;//declarations variables 60 | 61 | while (choice != 3)//enter 3 to quit program. 62 | { 63 | printf("Choose an option:\n1.) Convert Fahrenheit to Celsius.\n2.) Convert Celsius to Fahrenheit.\n3.) Quit the Program\n\n"); 64 | scanf_s("%i", &choice); 65 | switch (choice) 66 | { 67 | 68 | case 1: 69 | num1 = askNumFahrenheit(); 70 | num2 = convFahrenheit(num1); 71 | printCelsius(num2); 72 | break; 73 | 74 | 75 | case 2: 76 | num1 = askNumCelsius(); 77 | num2 = convCelsius(num1); 78 | printFahrenheit(num2); 79 | break; 80 | 81 | case 3: 82 | printf("\nend of program--need a Headache medicine-"); 83 | break; 84 | } 85 | }//end main 86 | system("pause"); 87 | 88 | } -------------------------------------------------------------------------------- /HW8inProgress.c: -------------------------------------------------------------------------------- 1 | /*programmer chase 2 | date 11/5/16 3 | specifications-switch problem. 1. Display the smallest number entered 4 | 2. Display the largest number entered 5 | 3. Display the sum of the five numbers entered 6 | 4. Display the average of the five numbers entered 7 | */ 8 | 9 | #include> 10 | #include> 11 | //main funtioin 12 | main() { 13 | 14 | //variable declarations 15 | int choice = 0, highNum = 1, lowNum = 2, sum = 3, avg = 4; 16 | //should average number be double????? 17 | 18 | printf("enter 5 numbers\n"); 19 | scanf_s(" %i %i %i %i" "%i", &choice, &highNum, &lowNum, &sum, &avg); 20 | printf("press 1 to enter smallest number\n"); 21 | printf("press 2 to enter largest number\n"); 22 | printf("press 3 to enter sum of numbers\n"); 23 | printf("press 4 to enter avg of numbers\n"); 24 | printf("select a number\n"); 25 | //use these numbers 18, 21, 17, 44, 9. 26 | scanf_s(" %i", &choice); 27 | 28 | 29 | 30 | 31 | 32 | switch (choice = 0) { 33 | 34 | 35 | //test case use numbers 1-5 36 | case '1': 37 | printf("%i is highNum", highNum); 38 | break; 39 | 40 | case '2': 41 | printf("%i is sum", sum);//the sum just list a number 42 | break; 43 | 44 | case '3': 45 | printf("%i is lowNum", lowNum);//third line shows smllest 46 | break; //the smallest entered was 1. 47 | 48 | case '4': 49 | printf("%i is avg", avg);//no avg is displayed 50 | break; 51 | 52 | default: 53 | printf("invalid number\n");//error messege here 54 | 55 | } 56 | printf("the smallest number is %i\n", lowNum); 57 | printf("the largest number is %i\n", highNum); 58 | printf("the sum of numbers is %i\n", sum); 59 | printf("the avg number is %.2lf\n", avg); 60 | 61 | 62 | system("pause"); 63 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 chase 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Quiz 6.c: -------------------------------------------------------------------------------- 1 | /*Programmers: Isaah Santos, Chase Singhofen, Brandt Barry 2 | Date: 12-1-16 3 | Specifications: Quiz 6*/ 4 | #include 5 | #include 6 | 7 | double circleInput() 8 | { 9 | double radius; 10 | printf("Please enter the radius of your circle:\n"); 11 | scanf_s("%lf", &radius); 12 | return radius; 13 | } 14 | 15 | double circleArea(double a) 16 | { 17 | double area; 18 | area = 3.14 * (a * a); 19 | return area; 20 | } 21 | 22 | double circleCircum(double a) 23 | { 24 | double circum; 25 | circum = 2 * 3.14 * a; 26 | return circum; 27 | } 28 | 29 | void displayCircle(double a, double b) 30 | { 31 | printf("The area of your circle is %.2lf\nThe circumference of your circle is %.2lf.\n", a, b); 32 | } 33 | 34 | double triangleBaseInput() 35 | { 36 | double base; 37 | printf("Please enter the base of the triangle:\n"); 38 | scanf_s("%lf", &base); 39 | return base; 40 | } 41 | 42 | double triangleHtInput() 43 | { 44 | double height; 45 | printf("Please enter the height of the triangle:\n"); 46 | scanf_s("%lf", &height); 47 | return height; 48 | } 49 | 50 | double triangleArea(double a, double b) 51 | { 52 | double tArea; 53 | tArea = (a * b) *0.5; 54 | return tArea; 55 | } 56 | 57 | void displayResults(double a) 58 | { 59 | printf("The area of your triangle is %.2lf\n", a); 60 | } 61 | 62 | double sqInput() 63 | { 64 | double length; 65 | printf("Please enter the length of the side of your square:\n"); 66 | scanf_s("%lf", &length); 67 | return length; 68 | } 69 | 70 | double sqArea(double a) 71 | { 72 | double area; 73 | area = a * a; 74 | return area; 75 | } 76 | 77 | double sqPeri(double a) 78 | { 79 | double perimeter; 80 | perimeter = a * 4; 81 | return perimeter; 82 | } 83 | 84 | void displayArea(double a, double b) 85 | { 86 | printf("The area of your square is %.2lf.\nThe perimeter is %.2lf.\n", a, b); 87 | } 88 | 89 | main() 90 | { 91 | int selection = 0; 92 | double a = 0.0, b = 0.0, area = 0.0, circum = 0.0, cnum1 = 0.0, cnum2 = 0.0, cnum3 = 0.0, tnum1 = 0.0, tnum2 = 0.0, tnum3 = 0.0, snum1 = 0.0, snum2 = 0.0, snum3 = 0.0; 93 | do 94 | { 95 | printf("Select an option from the following list:\n"); 96 | printf("1. Circle\n2. Triangle\n3. Square\n4. Exit\n"); 97 | scanf_s("%i", &selection); 98 | 99 | if (selection == 1) 100 | { 101 | cnum1 = circleInput(); 102 | cnum2 = circleArea(cnum1); 103 | cnum3 = circleCircum(cnum1); 104 | displayCircle(cnum2, cnum3); 105 | } 106 | 107 | else if (selection == 2) 108 | { 109 | tnum1 = triangleBaseInput(); 110 | tnum2 = triangleHtInput(); 111 | tnum3 = triangleArea(tnum1, tnum2); 112 | displayResults(tnum3); 113 | } 114 | 115 | else if (selection == 3) 116 | { 117 | snum1 = sqInput(); 118 | snum2 = sqArea(snum1); 119 | snum3 = sqPeri(snum1); 120 | displayArea(snum2, snum3); 121 | } 122 | 123 | else if (selection == 4) 124 | { 125 | printf("Thank you for using this program!\n"); 126 | } 127 | 128 | /*else 129 | { 130 | printf("That is not an option!\n"); 131 | }*/ 132 | } while (selection != 4); 133 | 134 | system("pause"); 135 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![done_c](https://user-images.githubusercontent.com/103309340/210172472-ddfe273d-70cc-473c-8f3f-edcf8da7d43c.gif) 2 | 3 | # 👨‍💻C-Programming Learner's Repository!👨‍💻 4 | 5 | 👋🏻 Welcome to the C Programming Learner's Repository! 6 | 7 | 👉This repository contains a collection of C programming exercises, examples, and projects to help you get started with learning C. 8 | 9 | Here's what you'll find in this repository:👇 10 | 11 | 📑Exercises: These are small programming problems designed to help you practice and improve your C skills. 12 | 13 | 📌Examples: These are complete C programs that demonstrate how to use various features of the language. 14 | 15 | 📓Projects: These are larger programming projects that put your skills to the test. 16 | 17 | 🤔What do you need to get started? 18 | Answer: To get started, you'll need a C compiler. If you don't already have one installed, you can download and install one for free from the internet. 19 | 20 | Check below for C Compiler installation guide suited to an operating system of your choice 👇: 21 | 22 | -To learn how to install a C compiler on Windows: https://linuxhint.com/install-c-compiler-windows/ 23 | 24 | -To learn to install GCC Compiler for Ubuntu (linux distro): https://data-flair.training/blogs/install-c-on-linux/ 25 | 26 | -To install GCC compiler on MacOS: https://codeforces.com/blog/entry/106465 27 | 28 | 29 | Once you have a C compiler installed, you can compile and run a C program by using the following steps: 30 | 31 | Open a terminal window. 32 | Navigate to the directory where your C program is saved. 33 | Type gcc followed by the name of your C program file, and then press Enter. For example: gcc main.c 34 | If the program compiles without errors, it will create an executable file. 35 | To run the program, type ./a.out and press Enter. 36 | We hope you find these resources helpful as you begin your journey to learn C programming. Good luck! 37 | 38 | Otherway is to download any code-editor according to convenience. 39 | Our recommendation is to download and install Microsoft's Visual Studio Code and further install some suitable program extensions. 40 | Link to install Visual Studio Code: https://code.visualstudio.com/download 41 | 42 | # README by Chase S. & Barsha D. 43 | 44 | ![resize_chase](https://user-images.githubusercontent.com/103309340/210171780-3867f9c6-a0d5-40bc-9d3a-ac3420aab9a7.jpg) & ![rsz_bd_gradient_1](https://user-images.githubusercontent.com/103309340/210171858-e62a5bd3-0ede-4314-8436-3c539a8a3434.jpg) 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /Switch (2)fromwill.c: -------------------------------------------------------------------------------- 1 | /*Programmer- 2 | Date- 3 | Specafication- */ 4 | //Preproccessor directives 5 | #include 6 | #include 7 | //main function 8 | main() { 9 | //Variable Decleration 10 | int choice=0; 11 | double r = 0,circle=0,side=0,square=0; 12 | while(choice != 3) 13 | { 14 | printf("Press 1 for area of circle\n"); 15 | printf("Press 2 for area of square\n"); 16 | printf("Press 3 to CY@\n"); 17 | scanf_s("%i", &choice); 18 | switch (choice) { 19 | case 1: 20 | printf("Enter the radius.\n\n"); 21 | scanf_s("%lf", &r); 22 | circle = 3.14*r*r; 23 | printf("Area of circle is %.2lf\n", circle); 24 | break; 25 | case 2: 26 | printf("Enter a side.\n"); 27 | scanf_s("%lf", &side); 28 | square = side*side; 29 | printf("Area of square is %.2lf\n\n", square); 30 | 31 | break; 32 | case 3: 33 | printf("=======================\n==========CY@==========\n=======================\n"); 34 | system("pause"); 35 | default: 36 | printf("you entered incorrect choice.\n"); 37 | 38 | 39 | 40 | } 41 | } 42 | //End main 43 | system("pause"); 44 | } -------------------------------------------------------------------------------- /Switch.c: -------------------------------------------------------------------------------- 1 | /*Programmer-Chase Singhofen 2 | Date- 3 | Specafication- */ 4 | //Preproccessor directives 5 | #include 6 | #include 7 | //main function 8 | void main() { 9 | //Variable Decleration 10 | int choice; 11 | float r ,circle,side,square; 12 | while(choice != 3) 13 | { 14 | printf("Press 1 for area of circle\n"); 15 | printf("Press 2 for area of square\n"); 16 | printf("Press 3 to CY@\n"); 17 | scanf("%d", &choice); 18 | switch (choice) { 19 | case 1: 20 | printf("Enter the radius.\n\n"); 21 | scanf("%f", &r); 22 | circle = 3.14*r*r; 23 | printf("Area of circle is %f\n", circle); 24 | break; 25 | case 2: 26 | printf("Enter a side.\n"); 27 | scanf("%f", &side); 28 | square = side*side; 29 | printf("Area of square is %f\n", square); 30 | 31 | break; 32 | case 3: 33 | printf("=======================\n==========CY@==========\n=======================\n"); 34 | system("pause"); 35 | default: 36 | printf("you entered incorrect choice.\n"); 37 | 38 | 39 | 40 | } 41 | } 42 | //End main 43 | system("pause"); 44 | } 45 | 46 | 47 | ______________________________________________________________________________________________________________ 48 | 49 | /*Programmer Chase Singhofen 50 | Date: 11/4/16 51 | Specifications: Switch : Case 1 ask user for radius of circle 52 | calculate area of circle, display area of circle 53 | case 2 ask for side of square, calculate area of square, display area of square*/ 54 | 55 | #include 56 | #include 57 | //main function 58 | void main() { 59 | //Variable Decleration 60 | int choice = 0; 61 | float r = 0, circle = 0, side = 0, square = 0; 62 | 63 | { 64 | while(choice!=3){ 65 | printf("Press 1 for area of circle\n"); 66 | printf("Press 2 for area of square\n"); 67 | printf("Press 3 to exit\n"); 68 | scanf("%d", &choice); 69 | switch (choice) { 70 | case 1: 71 | printf("Enter the radius.\n"); 72 | scanf("%f", &r); 73 | circle = 3.14*r*r; 74 | printf("Area of circle is %f\n", circle); 75 | break; 76 | case 2: 77 | printf("Enter a side.\n"); 78 | scanf("%f", &side); 79 | square = side*side; 80 | printf("Area of square is %f\n", square); 81 | break; 82 | case 3: 83 | printf("program terminated"); 84 | break; 85 | default: 86 | printf("you entered incorrect choice.\n"); 87 | break; 88 | } 89 | } 90 | } 91 | //End main 92 | system("pause"); 93 | } 94 | 95 | + 96 | -------------------------------------------------------------------------------- /SwitchlowNumOnly.c: -------------------------------------------------------------------------------- 1 | /*programmer chase 2 | date 11/5/16 3 | specifications-switch problem. 1. Display the smallest number entered 4 | 2. Display the largest number entered 5 | 3. Display the sum of the five numbers entered 6 | 4. Display the average of the five numbers entered 7 | */ 8 | 9 | #include> 10 | #include> 11 | //main funtioin 12 | main() { 13 | 14 | //variable declarations 15 | int choice = 0, highNum = 0, lowNum = 0, sum = 0, avg = 0; 16 | //should average number be double????? 17 | 18 | printf("enter 5 numbers\n"); 19 | scanf_s("%i %i %i %i %i",&lowNum, &highNum, &sum, &avg, &choice); 20 | 21 | //use these numbers 18, 21, 17, 44, 9. 22 | scanf_s(" %i", &lowNum); 23 | 24 | switch (choice = 0) { 25 | 26 | case '1': 27 | printf("%i is lowNum", lowNum);//third line shows smllest 28 | break; //the smallest entered was 1. 29 | } 30 | printf("the smallest number is %i\n", lowNum); 31 | 32 | system("pause"); 33 | } -------------------------------------------------------------------------------- /alternative method to switch using if else: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | //main function 4 | int main() 5 | { 6 | //Variable Decleration 7 | int choice; 8 | float r ,circle,side,square; 9 | while(choice != 3) 10 | { 11 | printf("Press 1 for area of circle\n"); 12 | printf("Press 2 for area of square\n"); 13 | printf("Press 3 to CY@\n"); 14 | scanf("%d", &choice); 15 | 16 | if(choice==1) 17 | { 18 | printf("Enter the radius.\n\n"); 19 | scanf("%f", &r); 20 | circle = 3.14*r*r; 21 | printf("Area of circle is %f\n", circle); 22 | } 23 | else if(choice==2) 24 | { 25 | printf("Enter a side.\n"); 26 | scanf("%f", &side); 27 | square = side*side; 28 | printf("Area of square is %f\n", square); 29 | } 30 | else if(choice==3) 31 | { 32 | printf("=======================\n=======================\n=======================\n"); 33 | } 34 | else 35 | { 36 | printf("you entered incorrect choice.\n"); 37 | } 38 | 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /arithmicoperations.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | 9/8/2016 3 | Specification-Addition*/ 4 | //Preprocessor directives 5 | 6 | 7 | #include 8 | #include 9 | 10 | //Main Funftion 11 | 12 | main() { 13 | 14 | int num1 = 0, num2 = 0, sum = 0; 15 | printf("Enter first number!:\n"); 16 | scanf_s("%i", &num1); 17 | scanf_s("%i", &num2); 18 | sum = num1 + num2; 19 | printf("The addtion is %i", sum); 20 | 21 | 22 | 23 | 24 | 25 | 26 | system("pause"); 27 | 28 | } //End Main 29 | 30 | -------------------------------------------------------------------------------- /arrayHW 9 in progress.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singhofen/c-programming/05d52ea8f7d2db896fac8c7c9923bdd5519b9b7c/arrayHW 9 in progress.c -------------------------------------------------------------------------------- /arrayINclassGrade.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singhofen/c-programming/05d52ea8f7d2db896fac8c7c9923bdd5519b9b7c/arrayINclassGrade.c -------------------------------------------------------------------------------- /assignment1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | main() { 5 | 6 | printf("Hello World!"); 7 | 8 | system("pause"); 9 | 10 | } -------------------------------------------------------------------------------- /assignment2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | main() { 5 | 6 | printf("Hello World!\n"); 7 | 8 | system("pause"); 9 | 10 | } -------------------------------------------------------------------------------- /assignment2revised.c: -------------------------------------------------------------------------------- 1 | /*Programmer - chase 2 | Date- 9/1/2016 3 | Hello World- First Program 4 | */ 5 | 6 | 7 | 8 | #include 9 | #include 10 | 11 | main() { 12 | 13 | printf("Hello World!\n"); 14 | 15 | system("pause"); 16 | 17 | } -------------------------------------------------------------------------------- /assignment7.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | main() { 4 | int userNumber = 0, sum = 0, count = 0, highNumber = 0, lowNumber = 0; 5 | double average; 6 | 7 | 8 | printf("enter a number greater than 0:(enter -1 to stop)\n"); 9 | scanf_s("%i", &userNumber); 10 | highNumber = userNumber; 11 | lowNumber = userNumber; 12 | 13 | while (userNumber != -1) 14 | { 15 | if (userNumber > lowNumber && userNumber > highNumber) { 16 | 17 | highNumber = userNumber; 18 | 19 | } 20 | else if (userNumber < lowNumber) 21 | 22 | lowNumber = userNumber; 23 | 24 | count = count + 1; 25 | sum = sum + userNumber; 26 | 27 | printf("Enter a number:(-1 to stop)\n"); 28 | scanf_s("%i", &userNumber); 29 | } 30 | average = (double)sum / count; 31 | 32 | printf("the sum is : %i\n", sum); 33 | printf("%i numbers were input \n", count); 34 | printf("the average is %.2lf\n", average); 35 | printf("the highest number entered was : %i\n", highNumber); 36 | 37 | printf("the lowest number entered was: %i\n", lowNumber); 38 | system("pause"); 39 | } -------------------------------------------------------------------------------- /assignment_7.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | Date: 10/26/16 3 | Specifications: Write C program that will allow user to enter infinite numbers one number 4 | at a time and all numbers greateer than zero. must have a way 5 | for user to stop entering values. once the user stops -screen 6 | will display highest, lowest, number of values entered, and avg of numbers */ 7 | 8 | #include 9 | #include 10 | main() { 11 | 12 | int userNumber = 0, sum = 0, count = 0, highNumber = 0, lowNumber = 0, lastNumber = 0; 13 | double average; 14 | 15 | 16 | printf("Enter a number greater than 0: (Enter -1 to stop) \n");//user number must be greater than zero or program doesnt run. 17 | scanf_s("%i", &userNumber);//user starts entering their numbers. 18 | highNumber = userNumber; 19 | lowNumber = userNumber; 20 | 21 | 22 | while (userNumber != -1) {//while loop lets user stop program using (-1)-- after entering infinite amount of numbers . 23 | if (userNumber > lowNumber && userNumber > highNumber)//conditions set for the user so when they enter any number 24 | highNumber = userNumber; // high or low- both the lowest and highest numbers are considered. 25 | 26 | else if (userNumber < lowNumber)//condition is set [IF] the if statement isnt acheived 27 | lowNumber = userNumber;//user number is recognized & gets low number. 28 | count = count + 1; 29 | sum = sum + userNumber;//user number plus the sum gets the sum of all entered numbers. 30 | 31 | printf("Enter a number:(-1 to stop)\n");//allows user to enter (-1) to stop or continue. 32 | scanf_s("%i", &userNumber);//user's number is displayed on screen. 33 | } 34 | average = (double)sum / count;//[casting!!] a variable. must use when finding an average or it will display as an INT, not double. 35 | //divides the count by the sum of numbers entered to calculate the average of total numbers entered by user. 36 | 37 | //statement below automaticlly show at end of program. 38 | printf(" The sum is: %i\n", sum);//sum appears on screen 39 | printf(" %i numbers were input\n", count);//number of numbers appears on screen 40 | printf(" The average is %.2lf\n", average);//average is displayed on screen 41 | printf("The highest number entered was: %i\n", highNumber);//highest number is displayed on screen 42 | printf("The last number entered was: %i\n", lastNumber);//last number is displayed on screen 43 | printf("The lowest number entered was: %i\n", lowNumber);//lowest number is displayed on screen 44 | system("pause"); 45 | } 46 | -------------------------------------------------------------------------------- /checkpoint4_mpg.c: -------------------------------------------------------------------------------- 1 | #include> 2 | #include 3 | main() { 4 | double miles, gallons, milesPerGallon;//sum up all of miles traveled and all of the gas used and then caluculate overall mpg using those total figures.use this to get overall mpg. 5 | double totalMiles = 0.0, totalGallons= 0.0, overallMilesPerGallon; 6 | //summary of whats going on. 7 | 8 | //priming read is prinf statement below. 9 | printf("Enter the gallons of gas used (-1 to quit):"); 10 | scanf_s("%lf", &gallons); 11 | //then a loop that checks for a sentinal value. 12 | while (gallons != -1) { 13 | totalGallons = totalGallons + gallons; 14 | printf("Enter the miles driven:"); 15 | scanf_s("%lf", &miles); 16 | 17 | milesPerGallon = miles / gallons;//calculation 18 | totalMiles = totalMiles + miles; 19 | printf("For this tak you got %.2lf miles per gallon.\n", milesPerGallon); 20 | //repeating read occurs at bottom of the loop 21 | printf("Enter the gallons of gas used (-1 to quit):"); 22 | scanf_s("%lf", &gallons); 23 | 24 | } 25 | overallMilesPerGallon = totalMiles / totalGallons;//additional calculation of overall miles which was accumulated inside the loop 26 | printf("Your average for these tanks is: %.2lf miles per gallon.\n", overallMilesPerGallon); 27 | system("pause"); 28 | } 29 | -------------------------------------------------------------------------------- /convertTemps.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | Date: 9/28/2016 3 | Specifications: Convert Temps 4 | */ 5 | 6 | #include 7 | #include 8 | 9 | main() //Main Function 10 | { 11 | double a = 5.0, b = 9.0, c = -32.0, result; 12 | result = (a / b) * (c); 13 | 14 | 15 | 16 | 17 | 18 | system("Pause"); 19 | }//End Main -------------------------------------------------------------------------------- /determining perfect number: -------------------------------------------------------------------------------- 1 | #include 2 | int func(int a){ 3 | int sum=0; 4 | 5 | for(int i=1;i 2 | int func(int a){ 3 | int sum=0; 4 | 5 | for(int i=1;i 2 | #include 3 | 4 | float poly(float a[], int, float); 5 | 6 | int main() 7 | { 8 | float x, a[10], y1; 9 | int d, i; 10 | 11 | printf("Enter polynomial equation degree: "); 12 | scanf("%d", &d); 13 | 14 | printf("Enter x value for which the equation is to be evaluated: "); 15 | scanf("%f", &x); 16 | 17 | for (i = 0; i <= d; i++) { 18 | printf("Enter x coeff to the power %d: ", i); 19 | scanf("%f", &a[i]); 20 | } 21 | 22 | y1 = poly(a, d, x); 23 | 24 | printf(" value of polynomial equation for the value of x = %.2f is: %.2f", x, y1); 25 | 26 | return 0; 27 | } 28 | 29 | float poly(float a[], int d, float x) 30 | { 31 | float p; 32 | int i; 33 | 34 | p = a[d]; 35 | 36 | for (i = d; i >= 1; i--) { 37 | p = (a[i - 1] + x * p); 38 | } 39 | 40 | return p; 41 | } 42 | -------------------------------------------------------------------------------- /digital clock creator: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int total_sec; 5 | int hours,minutes,seconds; 6 | printf("enter the number of seconds that shud be converted into digital clock form : "); 7 | scanf("%d",&total_sec); 8 | 9 | hours=total_sec/3600; 10 | minutes=(total_sec-hours*3600)/60; 11 | seconds=(total_sec-hours*3600)%60; 12 | 13 | if(hours<10){ 14 | printf(0); 15 | } 16 | printf("%d : ",hours); 17 | if(minutes<10){ 18 | printf(0); 19 | } 20 | printf("%d : ",minutes); 21 | if(seconds<10){ 22 | printf(0); 23 | } 24 | printf("%d",seconds); 25 | return 0; 26 | 27 | 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /digital clock creator using c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int total_sec; 5 | int hours,minutes,seconds; 6 | printf("enter the number of seconds that shud be converted into digital clock form : "); 7 | scanf("%d",&total_sec); 8 | 9 | hours=total_sec/3600; 10 | minutes=(total_sec-hours*3600)/60; 11 | seconds=(total_sec-hours*3600)%60; 12 | 13 | if(hours<10){ 14 | printf(0); 15 | } 16 | printf("%d : ",hours); 17 | if(minutes<10){ 18 | printf(0); 19 | } 20 | printf("%d : ",minutes); 21 | if(seconds<10){ 22 | printf(0); 23 | } 24 | printf("%d",seconds); 25 | return 0; 26 | 27 | 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /example1.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | date 10/25/2016 3 | Specifications:in class work*/ 4 | 5 | #include 6 | #include 7 | main() { 8 | 9 | int num = 1, sum = 0, i = 0, total = 4; 10 | double avg = 0; 11 | printf("enter four numbers\n"); 12 | 13 | for (i = 1; i < 4; i++) 14 | { 15 | scanf_s("%i\n", &num); 16 | sum = sum + num;//sum = sum + new number 17 | 18 | } 19 | avg = (double)sum / 4;//type casting 20 | printf("print average %lf\n", avg); 21 | 22 | system("pause"); 23 | } 24 | //end main -------------------------------------------------------------------------------- /exampleCounterN.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | main() 5 | 6 | { 7 | double n = 0; 8 | scanf_s("%lf", &n); 9 | 10 | int counter = 0; 11 | while (counter < n) { 12 | printf("HI"); 13 | counter++; 14 | }system("pause"); 15 | } -------------------------------------------------------------------------------- /factorials_checkpoint4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | main() { 4 | int number, factor=1, count; 5 | 6 | printf("Enter an integer: "); 7 | scanf_s("%i", &number); 8 | 9 | count = number; 10 | while (count >= 1) {//tried to debug program before entering(factor = factor * count) and it would not run so i had to use these factor loop 11 | //and multiply them 12 | factor = factor * count;//factor loop 4*3*2*1=24. trickiest part of loop 13 | //factor=1 which is multiplied by count which is 4 14 | //next time thru the loop we'll have 4*3 which is 12 then 12*2 which = 24. 15 | count = count - 1; 16 | } 17 | 18 | 19 | 20 | printf("The factorial: %i\n", factor); 21 | system("pause"); 22 | } -------------------------------------------------------------------------------- /final.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | Date 10/8/16 3 | Specifications: Ask the user to enter test scores. 4 | When they have entered all the tests scores, 5 | they will enter the value of -1. The Program 6 | will sum up all the scores entered, and output sum. 7 | 70, 80, 90, -1. Expected 240*/ 8 | 9 | #include 10 | #include 11 | 12 | main() { 13 | 14 | double score, sum = 0, grade = 0, gradeNum = 0, avg = 0, pass = 0, totalGrades = 0; 15 | printf("Enter a test score(-1 to quit):"); 16 | scanf_s("%lf", &grade); 17 | while (grade != -1) 18 | { 19 | 20 | if (grade <= 100 && grade >= 70) { 21 | pass++; 22 | printf("Pass: %.2lf\n", pass); 23 | } 24 | if (grade > 100 || grade <0) { 25 | printf("Error, grade is not in grade range\n"); 26 | } 27 | if (grade >= 0 && grade <= 100) { 28 | totalGrades++; 29 | } 30 | printf("Enter a test score(-1 to quit):"); 31 | scanf_s("%lf", &grade); 32 | } 33 | avg = 100 * pass / totalGrades; 34 | printf("\nThe percent of passing grades is : %.2lf\n", avg); 35 | system("pause"); 36 | 37 | } -------------------------------------------------------------------------------- /findavegrades2.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | Date: 9/13/2016 3 | Specifications: Finding average grades*/ 4 | 5 | //*Programmer directions 6 | 7 | #include 8 | #include 9 | 10 | main() // Mian Funtion 11 | { 12 | double t1 = 0, t2 = 0, t3 = 0, t4 = 0; // Variable Declaratives 13 | double average = 0, A = 90, B = 80, C = 70, D = 60, F = 50; 14 | printf("Enter the four test scores here \n"); //Prompting user to enter grades 15 | scanf_s("%lf %lf %lf %lf ", &t1, &t2, &t3, &t4); // Input from user 16 | average = (t1 + t2 + t3 + t4 / 4); 17 | printf("The average grade is %.2lf \n", average); // Shows averge to user 18 | if (average >= A) 19 | printf("The letter grade is A \n"); 20 | else if (average >=B) 21 | printf("The letter grade is B \n"); 22 | else if (average >=C) 23 | printf("The letter grade is C \n"); 24 | else if (average >=D) 25 | printf("The letter grade is D \n"); 26 | else 27 | printf("The letter grade is F \n"); 28 | 29 | system("pause"); 30 | } -------------------------------------------------------------------------------- /functions.c: -------------------------------------------------------------------------------- 1 | /*programmer - chase 2 | functions in class 11/22/16 3 | use of functions*/ 4 | 5 | #include 6 | #include 7 | #include 8 | void myFuntion(int a)//passing value to function (int a). of type int."how to pass" 9 | { 10 | //printf("this is my function\n a = %i\n\n", a); 11 | printf("this is my function\n"); 12 | }//end myfunction 13 | 14 | main()//main doesnt know what my function is.(5) 15 | { 16 | int a; 17 | printf("this is main function.\n a = %i\n\n",a); 18 | myFunction(5);//CALLED OR INVOKED MY FUNCTION //int a is replaced by (5) 19 | system("pause"); 20 | 21 | int shape1, shape2; 22 | int square(int a); 23 | 24 | { 25 | printf("this is square\n"); 26 | shape1 = askSquare(); 27 | shape2 = askCube(); 28 | } 29 | int cube(int a); 30 | printf("this is cube\n"); 31 | shape1 = askSquare(); 32 | shape2 = askCube(); 33 | 34 | }//end main 35 | 36 | int askNum() 37 | { 38 | int x; 39 | printf("enter a number\n"); 40 | scanf_s("%i", &x); 41 | return x; 42 | 43 | } 44 | 45 | int addNum(int a, int b)//parameters or arguments 46 | { 47 | int sum; 48 | sum = a + b; 49 | return sum; 50 | } 51 | void display(int a) 52 | { 53 | printf("the result is %i\n", a); 54 | 55 | 56 | 57 | 58 | 59 | int num1, num2, num3, prod; 60 | //printf("this is main funtion\n"); 61 | num1 = askNum ();//invoking 62 | num2 = askNum();//invoking 63 | addNum(num1 , num2); 64 | num3 = addNum(num1, num2);//2 argumnents 65 | //prod = multi(num1, num2); 66 | display(num3); 67 | //display(1000); 68 | //printf("the additions is %i\n", num3); 69 | //myfunctions(1); 70 | //myfunction(5); 71 | 72 | system("pause"); 73 | }//end main 74 | 75 | 76 | //google all function, you can create your own functions. 77 | 78 | 79 | -------------------------------------------------------------------------------- /funtions.c: -------------------------------------------------------------------------------- 1 | /*programmer - chase 2 | functions in class 11/22/16 3 | use of functions*/ 4 | 5 | #include 6 | #include 7 | #include 8 | void myFuntion(int a)//passing value to function (int a). of type int."how to pass" 9 | { 10 | //printf("this is my function\n a = %i\n\n", a); 11 | printf("this is my function\n"); 12 | }//end myfunction 13 | 14 | main()//main doesnt know what my function is.(5)if left blank 15 | { 16 | int a; 17 | //printf("this is main function.\n a = %i\n\n", a);//error messege cant figure out 18 | myFunction(5);//CALLED OR INVOKED MY FUNCTION //int a is replaced by (5) 19 | system("pause"); 20 | 21 | int shape1, shape2;//sarting here is where i'm a little confused. havent ran yet. 22 | int square(int a); 23 | 24 | { 25 | printf("this is square\n"); 26 | shape1 = askSquare(); 27 | shape2 = askCube(); 28 | } 29 | int cube(int a); 30 | printf("this is cube\n"); 31 | shape1 = askSquare(); 32 | shape2 = askCube(); 33 | 34 | }//end main 35 | 36 | int askNum() 37 | { 38 | int x; 39 | printf("enter a number\n"); 40 | scanf_s("%i", &x); 41 | return x; 42 | 43 | } 44 | 45 | int addNum(int a, int b)//parameters or arguments 46 | { 47 | int sum; 48 | sum = a + b; 49 | return sum; 50 | } 51 | void display(int a) 52 | { 53 | printf("the result is %i\n", a); 54 | 55 | 56 | 57 | 58 | 59 | int num1, num2, num3, prod; 60 | //printf("this is main funtion\n"); 61 | num1 = askNum();//invoking 62 | num2 = askNum();//invoking 63 | addNum(num1, num2); 64 | num3 = addNum(num1, num2);//2 argumnents 65 | //prod = multi(num1, num2); 66 | display(num3); 67 | //display(1000); 68 | //printf("the additions is %i\n", num3); 69 | //myfunctions(1); 70 | //myfunction(5); 71 | 72 | system("pause"); 73 | }//end main 74 | //google all functions, you can create your own functions. 75 | 76 | 77 | -------------------------------------------------------------------------------- /games_using_c.c: -------------------------------------------------------------------------------- 1 | //********************Guess The Number**************************// 2 | #include 3 | #include 4 | #include 5 | 6 | int main(){ 7 | int number, guess, nguesses=1; 8 | srand(time(0)); 9 | number = rand()%100 + 1; // Generates a random number between 1 and 100 10 | // printf("The number is %d\n", number); 11 | // Keep running the loop until the number is guessed 12 | do{ 13 | printf("Guess the number between 1 to 100\n"); 14 | scanf("%d", &guess); 15 | if(guess>number){ 16 | printf("Lower number please!\n"); 17 | } 18 | else if(guess 32 | #include 33 | #include 34 | 35 | int snakeWaterGun(char you, char comp){ 36 | // returns 1 if you win, -1 if you lose and 0 if draw 37 | // Condition for draw 38 | // Cases covered: 39 | // ss 40 | // gg 41 | // ww 42 | if(you == comp){ 43 | return 0; 44 | } 45 | 46 | // Non-draw conditions 47 | // Cases covered: 48 | // sg 49 | // gs 50 | // sw 51 | // ws 52 | // gw 53 | // wg 54 | 55 | 56 | if(you=='s' && comp=='g'){ 57 | return -1; 58 | } 59 | else if(you=='g' && comp=='s'){ 60 | return 1; 61 | } 62 | 63 | if(you=='s' && comp=='w'){ 64 | return 1; 65 | } 66 | else if(you=='w' && comp=='s'){ 67 | return -1; 68 | } 69 | 70 | if(you=='g' && comp=='w'){ 71 | return -1; 72 | } 73 | else if(you=='w' && comp=='g'){ 74 | return 1; 75 | } 76 | 77 | } 78 | int main(){ 79 | char you, comp; 80 | srand(time(0)); 81 | int number = rand()%100 + 1; 82 | 83 | if(number<33){ 84 | comp = 's'; 85 | } 86 | else if(number>33 && number<66){ 87 | comp='w'; 88 | } 89 | else{ 90 | comp='g'; 91 | } 92 | 93 | printf("Enter 's' for snake, 'w' for water and 'g' for gun\n"); 94 | scanf("%c", &you); 95 | int result = snakeWaterGun(you, comp); 96 | if(result ==0){ 97 | printf("Game draw!\n"); 98 | } 99 | else if(result==1){ 100 | printf("You win!\n"); 101 | } 102 | else{ 103 | printf("You Lose!\n"); 104 | } 105 | printf("You chose %c and computer chose %c. ", you, comp); 106 | return 0; 107 | } -------------------------------------------------------------------------------- /gradesArray.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singhofen/c-programming/05d52ea8f7d2db896fac8c7c9923bdd5519b9b7c/gradesArray.c -------------------------------------------------------------------------------- /gradesforclass.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | Date: 9/13/2016 3 | Specifications: Finding average grades*/ 4 | 5 | //*Programmer directions 6 | 7 | #include 8 | #include 9 | 10 | //main funtion 11 | 12 | main() 13 | 14 | { 15 | //Variable declarations 16 | double grade1, grade2, grade3, avg; 17 | //user input 18 | printf("Enter three grades:\n"); 19 | scanf_s("%lf %lf %lf", &grade1, &grade2, &grade3); 20 | //check 21 | printf("grades entered are %.2lf, %.2lf, %.2lf\n", grade1, grade2, grade3); 22 | //process 23 | avg = (grade1 + grade2 + grade3) / 3; 24 | printf("Average of the grades %.2lf %.2lf %.2lf is %.2lf\n", grade1, grade2, grade3, avg); 25 | if (avg >= 90) 26 | printf("Your grade is A \n"); 27 | else if (avg >= 80) 28 | printf("Your grade is B \n"); 29 | else if (avg >= 70) 30 | printf("Your grade is C \n"); 31 | else if (avg >= 60) 32 | printf("Your grade is D \n"); 33 | else 34 | printf("Your grade is F \n"); 35 | 36 | 37 | 38 | 39 | 40 | 41 | system("pause"); 42 | 43 | 44 | } 45 | //end main 46 | -------------------------------------------------------------------------------- /gradesforclassavg.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | Date: 9/13/2016 3 | Specifications: Finding average grades*/ 4 | 5 | //*Programmer directions 6 | 7 | #include 8 | #include 9 | 10 | //main funtion 11 | 12 | main() 13 | 14 | { 15 | //Variable declarations 16 | double grade1, grade2, grade3, avg; 17 | //user input 18 | printf("Enter three grades:\n"); 19 | scanf_s("%lf %lf %lf", &grade1, &grade2, &grade3); 20 | //check 21 | printf("grades entered are %.2lf, %.2lf, %.2lf\n", grade1, grade2, grade3); 22 | //process 23 | avg = (grade1 + grade2 + grade3) / 3; 24 | printf("Average of the grades %.2lf %.2lf %.2lf is %.2lf\n", grade1, grade2, grade3, avg); 25 | if (avg >= 90) 26 | printf("Your grade is A \n"); 27 | else if (avg >= 80) 28 | printf("Your grade is B \n"); 29 | else if (avg >= 70) 30 | printf("Your grade is C \n"); 31 | else if (avg >= 60) 32 | printf("Your grade is D \n"); 33 | else 34 | printf("Your grade is F \n"); 35 | 36 | 37 | 38 | 39 | 40 | 41 | system("pause"); 42 | 43 | 44 | } 45 | //end main 46 | -------------------------------------------------------------------------------- /helloworld.c: -------------------------------------------------------------------------------- 1 | /*Programmer - chase 2 | Date- 9/1/2016 3 | Hello World- First Program 4 | */ 5 | 6 | 7 | 8 | #include 9 | #include 10 | 11 | main() { 12 | 13 | printf("Hello World!\n"); 14 | 15 | system("pause"); 16 | 17 | } -------------------------------------------------------------------------------- /homework10roughdraft.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singhofen/c-programming/05d52ea8f7d2db896fac8c7c9923bdd5519b9b7c/homework10roughdraft.c -------------------------------------------------------------------------------- /homework8.c: -------------------------------------------------------------------------------- 1 | /*Programmer:Chase Singhofen 2 | Date: 11/12/16 3 | Specification:Write switch program that tells user to input 5 numbers, then asks them to choose 4 | option to display smallest, largest, sum and the avg. perform program 5 times including one invalid 5 | statement. 6 | */ 7 | 8 | //preprocessors 9 | #include 10 | #include 11 | //main function 12 | main() { 13 | //variable declaration 14 | int choice = 0, sum = 0, q = 0, num = 0, small, large; 15 | double avg = 0; 16 | //user enters a number 17 | printf("Please enter a number.\n");//enter number by user 18 | scanf_s("%i", &q);//user enters number 19 | 20 | small = q; 21 | large = q; 22 | //start while loops. user will have oppourtunity to enter 5 numbers unless he enters 23 | // 5 to quit program. 24 | while (num < 4) 25 | { 26 | num++; //count increment +1 27 | sum = sum + q; 28 | 29 | if (small > q)//int small is greater than int q 30 | small = q; //line 30 will determine smallest integer entered by user 31 | 32 | else if (large < q)//int large is less than int q 33 | large = q; //line 33 will determine largest integer entered by user 34 | 35 | else 36 | q = q;//gets number 37 | 38 | printf("Please enter another number.\n"); 39 | scanf_s("%i", &q);//user will enter another number 40 | } 41 | sum = sum + q; 42 | 43 | 44 | if (small > q)//int small is greater than int q 45 | small = q; //line 47 will determine smallest integer entered by user 46 | 47 | else if (large < q) //int large is less than int q 48 | large = q; //line 50 will determine largest integer entered by user 49 | 50 | else 51 | q = q;//gets number 52 | 53 | while (choice != 5)//the user choice cannot = 5!. press 5 to exit program. 54 | { 55 | { 56 | 57 | } //while loops end. 58 | printf("Please choose an option.\n"); 59 | printf("press 1 to View smallest number.\n"); 60 | printf("press 2 to View largest number.\n"); 61 | printf("press 3 to View the sum.\n"); 62 | printf("press 4 to View the average.\n"); 63 | printf(" press 5 to Quit program\n"); 64 | scanf_s("%i", &choice); 65 | switch (choice)//switch starts. user can display small, large avg, & sum of thier numbers. 66 | //by choosing option:1-5. 67 | { 68 | case 1: 69 | printf("%i\n\n", small); 70 | break; 71 | 72 | case 2: 73 | printf("%i\n\n", large); 74 | break; 75 | 76 | case 3: 77 | printf("%i\n\n", sum); 78 | break; 79 | 80 | case 4: 81 | avg = (double)sum / 5; //type casting to keep double 82 | printf("%.2lf\n\n", avg);//avg displayed 83 | break; 84 | 85 | case 5: 86 | printf("END OF SWITCH PROGRAM.\n"); 87 | break; 88 | 89 | default: 90 | printf("INVALID NUMBER!!!.\n\n"); 91 | break; 92 | } 93 | } 94 | //user prompt 95 | //end main function 96 | system("pause"); 97 | } 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /hw10.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | main() 6 | { 7 | int celsius, fahrenheit = 0, condition = 0, temperture = 0; 8 | 9 | 10 | 11 | while (condition != -1) 12 | { 13 | 14 | printf("\nEnter temp in celsius:"); 15 | scanf_s("%i", &celsius); 16 | 17 | 18 | 19 | fahrenheit = (celsius * 1.8) + 32; 20 | printf("\n temp in fahrenheit :%i ", fahrenheit); 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | printf("\nEnter temp in fahrenheit:"); 29 | scanf_s("%i", &fahrenheit); 30 | 31 | 32 | 33 | celsius = (fahrenheit - 32) / 1.8; 34 | printf("\n temp in celsius :%i ", celsius); 35 | 36 | 37 | 38 | 39 | 40 | printf("\ncontinue -1 to exit", &condition); 41 | scanf_s("%i", &condition); 42 | 43 | } 44 | 45 | system("pause"); 46 | } 47 | 48 | 49 | 50 | 51 | /* 52 | 53 | //examples and examples of prototypes. 54 | int multi(int a); 55 | void cube(int a); 56 | 57 | main(void) { 58 | 59 | int var; 60 | 61 | var = multi(4); //16 62 | 63 | printf("%i\n", var); 64 | 65 | printf("%i\n", multi(9)); 66 | 67 | } 68 | 69 | void cube(int a) {//function definitions. 70 | 71 | int result; 72 | 73 | result = a*a*a; 74 | 75 | printf("%i", result); 76 | } 77 | 78 | int multi(int a) {//example of another functions 79 | 80 | int result; 81 | 82 | result = a * a; 83 | 84 | return result; 85 | }*/ 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /hw10inProgress.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | void temp(double a, double b, double c, double d); 6 | 7 | int main(void) 8 | { 9 | double(a) (b) (c); 10 | 11 | 12 | 13 | degree(a, b, c ); 14 | { 15 | int celsius, fahrenheit; 16 | 17 | printf("\nEnter temp in celsius:"); 18 | scanf_s("%i", &celsius); 19 | 20 | fahrenheit = (celsius * 1.8) + 32; 21 | printf("\n temp in fahrenheit :%i ", fahrenheit); 22 | 23 | 24 | printf("\nEnter temp in fahrenheit:"); 25 | scanf_s("%i", &fahrenheit); 26 | 27 | celsius = (fahrenheit - 32) / 1.8; 28 | printf("\n temp in celsius :%i ", celsius); 29 | 30 | system("pause"); 31 | } 32 | 33 | 34 | -------------------------------------------------------------------------------- /hw5.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | Date 10/8/16 3 | Specifications: Ask the user to enter test scores. 4 | When they have entered all the tests scores, 5 | they will enter the value of -1. The Program 6 | will find total percent of passing grades and exclude failing 7 | grades*/ 8 | 9 | #include 10 | #include 11 | 12 | main() { 13 | //variables and declarations, while loop- grade cannot = -1. 14 | double score, sum = 0, grade = 0, gradeNum = 0, avg = 0, pass = 0, totalGrades = 0; 15 | printf("Enter a test score(-1 to quit):"); 16 | scanf_s("%lf", &grade); 17 | while (grade != -1) 18 | { 19 | // if statement where grade is less than or equal to 100 & grade is greater than or equal to 70. 20 | // present passing grade if grades or in range. 21 | // in this if statement the grades cannot be lower than 70 or higher than 100. 22 | 23 | if (grade <= 100 && grade >= 70) { 24 | pass++; 25 | printf("Pass: %.2lf\n", pass); 26 | //if statement where grade is greater than 100 and less than zero. 27 | // present error messege if any entered grades are greater than 100 or less than 0. 28 | } 29 | if (grade > 100 || grade <0) { 30 | printf("Error, grade is not in grade range\n"); 31 | 32 | //total grades that are greater or equal to 0 and less than or equal to 100. 33 | 34 | } 35 | if (grade >= 0 && grade <= 100) { 36 | totalGrades++; 37 | 38 | //enter test scores here 39 | } 40 | printf("Enter a test score(-1 to quit):"); 41 | scanf_s("%lf", &grade); 42 | 43 | //statement that divides the total passing grades by 100 to get average 44 | //of passing grades. 45 | } 46 | avg = 100 * pass / totalGrades; 47 | printf("\nThe percent of passing grades is : %.2lf\n", avg); 48 | system("pause"); 49 | 50 | } -------------------------------------------------------------------------------- /hw5avgTestgrades.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | Date 10/8/16 3 | Specifications: Ask the user to enter test scores. 4 | When they have entered all the tests scores, 5 | they will enter the value of -1. The Program 6 | will sum up all the scores entered, and output sum. 7 | 70, 80, 90, -1. Expected 240*/ 8 | 9 | 10 | #include 11 | #include 12 | 13 | 14 | 15 | main() { 16 | 17 | double score, sum = 0, grade = 0, gradeNum = 0, avg = 0, pass = 0, totalGrades = 0; 18 | printf("Enter a test score(-1 to quit):"); 19 | scanf_s("%lf", &grade); 20 | while (grade != -1) 21 | { 22 | 23 | if (grade <= 100 && grade >= 70) { 24 | pass++; 25 | printf("Pass: %.2lf\n", pass); 26 | } 27 | if (grade > 100 || grade <0) { 28 | printf("Error, grade is not in grade range\n"); 29 | } 30 | if (grade >= 0 && grade <= 100) { 31 | totalGrades++; 32 | } 33 | printf("Enter a test score(-1 to quit):"); 34 | scanf_s("%lf", &grade); 35 | } 36 | avg = 100 * pass / totalGrades; 37 | printf("\nThe percent of passing grades is : %.2lf\n", avg); 38 | system("pause"); 39 | 40 | } -------------------------------------------------------------------------------- /hw5inclass.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | Date 10/8/16 3 | Specifications: Ask the user to enter test scores. 4 | When they have entered all the tests scores, 5 | they will enter the value of -1. The Program 6 | will sum up all the scores entered, and output sum. 7 | 70, 80, 90, -1. Expected 240*/ 8 | 9 | 10 | #include 11 | #include 12 | 13 | main() { 14 | 15 | double score, sum = 0, grade = 0, gradeNum = 0, avg = 0, pass = 0, totalGrades = 0; 16 | 17 | while (grade != -1) { 18 | 19 | printf("Enter a test score(-1 to quit):"); 20 | scanf_s("%.2lf", &grade); 21 | 22 | 23 | if (grade <= 100 && grade >= 70) { 24 | 25 | pass++; 26 | printf("Pass: %lf\n", pass); 27 | } 28 | if (grade >= 100) { 29 | printf("Error, grade is not in grade range\n"); 30 | } 31 | if (grade >= 0 && grade <= 100) { 32 | totalGrades++; 33 | } 34 | 35 | } 36 | avg = (pass / totalGrades)*100; 37 | printf("\nThe avg of the scores is : %.2lf\n", avg); 38 | system("pause"); 39 | 40 | } -------------------------------------------------------------------------------- /hw5inclassSample.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | Date 10/8/16 3 | Specifications: Ask the user to enter test scores. 4 | When they have entered all the tests scores, 5 | they will enter the value of -1. The Program 6 | will sum up all the scores entered, and output sum. 7 | 70, 80, 90, -1. Expected 240*/ 8 | 9 | 10 | #include 11 | #include 12 | 13 | main() { 14 | 15 | double score, sum = 0, grade = 0, gradeNum = 0, avg = 0, pass = 0, totalGrades = 0; 16 | printf("Enter a test score(-1 to quit):"); 17 | scanf_s("%.2lf", &grade); 18 | while (grade != -1) 19 | { 20 | 21 | if (grade <= 100 && grade >= 70) { 22 | pass++; 23 | printf("Pass: %.2lf\n", pass); 24 | } 25 | if (grade > 100 || grade <0) { 26 | printf("Error, grade is not in grade range\n"); 27 | } 28 | if (grade >= 0 && grade <= 100) { 29 | totalGrades++; 30 | } 31 | printf("Enter a test score(-1 to quit):"); 32 | scanf_s("%.2lf", &grade); 33 | } 34 | avg = 100 * pass / totalGrades; 35 | printf("\nThe avg of the scores is : %.2lf\n", avg); 36 | system("pause"); 37 | 38 | } -------------------------------------------------------------------------------- /hw6_partA.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | Date 10/18/16 3 | Specifications: Write a program that will Create a 4 | loop that will output all the multiples of 5 5 | that are greater than zero and less than 60 (do not include 60) 6 | */ 7 | 8 | 9 | 10 | #include 11 | #include 12 | 13 | main() 14 | { 15 | int i; 16 | for (i = 5; i < 60; i++) {//greater than zero and less than 60 17 | if (i % 5 == 0)//equal too 18 | { 19 | printf("\n%i", i); 20 | } 21 | } 22 | system("pause"); 23 | } -------------------------------------------------------------------------------- /hw6_partB.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | Date 10/18/16 3 | Specifications: Create a loop that will output 4 | all the numbers less than 200 that are evenly 5 | divisible by both 2 and 7. 6 | */ 7 | 8 | 9 | 10 | #include 11 | #include 12 | main() 13 | 14 | 15 | { 16 | 17 | int counter = 0; 18 | 19 | while (counter <= 200) { 20 | if (counter % 2 == 0 && counter % 7 == 0) 21 | 22 | printf("\n%i", counter); 23 | counter++; 24 | 25 | } 26 | system("pause"); 27 | } 28 | 29 | -------------------------------------------------------------------------------- /hw6_partC.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | main() 4 | { 5 | int number = 8, count = 0, multiple = 0, sum = 0; 6 | 7 | while (multiple < 500) { 8 | multiple = number * count; 9 | count = ++count; 10 | if (multiple > 100) { 11 | printf("Your multiple is: %i \n", multiple); 12 | 13 | //the code above generates multiples of 8 but 14 | //starting at 104 ending at 504. 15 | 16 | sum = multiple * count; 17 | count = ++count; 18 | printf("Your sum of the multiples are: %i \n", sum); 19 | //all the code shown here generates a large sum of the multiples 20 | 21 | system("pause"); 22 | } 23 | } 24 | } 25 | 26 | ____________________________________________________________________________________________________________________________________ 27 | 28 | #include 29 | #include 30 | main() 31 | { 32 | int number = 8, count = 0, multiple = 0, sum = 0; 33 | 34 | while (multiple < 500) { 35 | multiple = number * count; 36 | count = ++count; 37 | if (multiple > 100) { 38 | printf("Your multiple is: %i \n", multiple); 39 | 40 | //the code above generates multiples of 8 but 41 | //starting at 104 ending at 504. 42 | 43 | sum = multiple + count;//using this it gives me multiples of 16 and sum (+count or *count) 44 | count = ++count; 45 | printf("Your sum of the multiples are: %i \n", sum); 46 | //all the code shown here generates a large sum of the multiples by 16 47 | system("pause"); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /hw6_partC_final.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | main() 4 | { 5 | int sum = 0; 6 | for (int i = 1; i <=400; i++) 7 | { 8 | if (i % 8 == 0) 9 | { 10 | sum++; 11 | 12 | } 13 | } 14 | printf("the sum of the multiples of 8 is %i\n", sum); 15 | 16 | system("pause"); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /hw6_partD.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | Date 10/18/16 3 | Specifications: Create a loop that will output 4 | the sum of all odd numbers between 20 and 100. 5 | */ 6 | 7 | 8 | 9 | #include 10 | #include 11 | main() 12 | { 13 | printf("Odd numbers between 20 to 100\n"); 14 | 15 | int counter = 0; 16 | for (counter = 20; counter <= 100; counter++) {//the counter will start at 20 and not exceed 100. 17 | 18 | if (counter % 2 == 1) { // odd numbers do not divide evenly. odd numbers leave a remainder of 1. 19 | //if counter number is divisible it will not print odd numbers 20 | //because there will be no remainder. 21 | 22 | printf("%i ", counter);// print all odd numbers. 23 | } 24 | } 25 | system("pause"); 26 | } -------------------------------------------------------------------------------- /hw9.c: -------------------------------------------------------------------------------- 1 | /*Programmer: Chase Singhofen 2 | Date: 3 | Specification:Homework 9. Array Function. 4 | */ 5 | 6 | //preprocessors 7 | #include 8 | #include 9 | #define SIZE 50 10 | //main function. 11 | //printf(enter number and (-999 = quit ) 12 | //use for and if statements 2 each, one for input and one for output. 13 | main() { 14 | int number[SIZE];// size is [50] 15 | int i;// should be in []along with variable int. 16 | 17 | for (i = 0; i < SIZE; i++) //remember to put value = 0 with the integer [i] in for loop statement. 18 | { 19 | printf("enter a value for array (-999 to quit)\n\n"); 20 | scanf_s("%i", &number[i]); 21 | if (number[i] == -999) { 22 | break; //break the for loop and no more inputs.. 23 | } 24 | }//end for statement 25 | 26 | for (i = 0; i < SIZE; i++) 27 | { 28 | printf("%i, %i\n", i + 1, number[i]); 29 | if (number[i] == -999) { 30 | break;//break the for loop and no more outputs will be allowed.. 31 | // the break statements will not allow anymore input numbers to be entered. 32 | //This will automatically display all input numbers [50] that were entered. 33 | //SIZE value is [50]. 34 | } 35 | 36 | }//end for and if statements. 37 | //end main function 38 | system("pause"); 39 | } 40 | -------------------------------------------------------------------------------- /hw9FINAL.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singhofen/c-programming/05d52ea8f7d2db896fac8c7c9923bdd5519b9b7c/hw9FINAL.c -------------------------------------------------------------------------------- /hw9final.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singhofen/c-programming/05d52ea8f7d2db896fac8c7c9923bdd5519b9b7c/hw9final.c -------------------------------------------------------------------------------- /inclass.c: -------------------------------------------------------------------------------- 1 | /*programmer Chase Singhofen 2 | date 10/18/16 3 | specifications 4 | */ 5 | 6 | #include 7 | #include 8 | main() 9 | 10 | { 11 | int value = 0, count = 0, num = 0; 12 | scanf_s("%i", &value); 13 | while (count < value) 14 | { 15 | printf("enter a number\n"); 16 | scanf_s("%i", &num); 17 | count++; 18 | } 19 | 20 | 21 | system("pause"); 22 | 23 | } -------------------------------------------------------------------------------- /input.c: -------------------------------------------------------------------------------- 1 | // ConsoleApplication1.cpp : Defines the entry point for the console application. 2 | /*Programmer Chase Singhofen 3 | Date 9/6/2016 4 | Specifications: Take the input from the user and output it 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | 11 | 12 | main() 13 | { 14 | double a = 0.0; //Initialize Variables 15 | double b = 0.0; 16 | double c = 0.0; 17 | 18 | printf("please enter a numbers(decimals):\n"); //Prompt user to input 19 | scanf_s("%lf %lf %lf", &a , &b , &c); //Take input 20 | 21 | 22 | printf("the number entered is %lf, %lf, %lf \n", a , b, c); //Display input 23 | system("pause"); //Pause the console 24 | 25 | } 26 | 27 | -------------------------------------------------------------------------------- /logicalOperators.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | Date 10/8/2016 3 | Specifications: Logical Operators*/ 4 | 5 | //Creating small program to see if they will be true or false statements. 6 | 7 | #include 8 | #include 9 | 10 | main() 11 | 12 | { 13 | int a = 10, b = 6, c = 4; 14 | 15 | 16 | if (a <= b || c >= 4) 17 | printf_s("First Condition is TRUE!\n"); 18 | 19 | if ( c < a && a == 10) 20 | printf_s("Second Condition is FALSE!"); 21 | 22 | if (!(b==c + 6)) 23 | printf_s("Third Condition is TRUE!"); 24 | 25 | 26 | system("pause"); 27 | } -------------------------------------------------------------------------------- /nested_for_loops.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | main() 4 | { 5 | 6 | int i, j;//variables 7 | for (i = 1; i <= 5; i++)//the i<=5 determines how many rows will print. 8 | 9 | { 10 | for (j = 1; j <= i; j++)//inner for loop controls how many times the * gets printed or whatever you want to be 11 | //be printed in the printf statment.object-oriented programming language that's designed to be portable and workable on as many 12 | { 13 | printf("3"); 14 | } 15 | printf("\n"); 16 | } 17 | system("pause"); 18 | } -------------------------------------------------------------------------------- /numbers.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | Date: 9/13/2016 3 | Specifications:input output numbers */ 4 | 5 | //*Programmer directions: Enter numbers greater, smaller, and equal. 6 | 7 | #include 8 | #include 9 | 10 | main()//main functions 11 | { 12 | int num1, num2, messege1, messege2, messege3; //Variable declarations 13 | printf("Enter two numbers here! \n");//user prompt 14 | scanf_s("%lf %lf", &num1, &num2); 15 | 16 | printf("First number is greater than second number \n"); 17 | scanf_s("%lf %lf", &num1, &num2); 18 | 19 | printf("First number is smaller than second number \n"); 20 | scanf_s("%lf %lf", &num1, &num2); 21 | 22 | printf("Got it! Both numbers are the same!\n"); 23 | scanf_s("%lf %lf", &num1, &num2); 24 | 25 | system("pause"); 26 | }//end main 27 | -------------------------------------------------------------------------------- /operators.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | date:09/27/2016 3 | Comparitive Operators*/ 4 | 5 | //Programmer Directives: Comparitive Operators 6 | 7 | #include 8 | #include 9 | //main function 10 | main() { 11 | //variable declarations 12 | int num1 = 0, num2 = 0; 13 | //user prompt 14 | printf("Enter the two numbers \n"); 15 | scanf_s("%i %i", &num1, &num2); 16 | printf("You entered %i, %i\n", num1, num2); 17 | { 18 | if (num1, num2); 19 | printf("Number 1 is greater,\n"); 20 | } 21 | /*else if (num1 > num2); 22 | { 23 | else 24 | } 25 | printf("\nBoth mubers are the same!\n");*/ 26 | 27 | 28 | system("pause"); 29 | 30 | } 31 | 32 | -------------------------------------------------------------------------------- /periIncheslenghtsquare.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | Date: 9/13/2016 3 | Specifications: Finding Length Square and Perimeter*/ 4 | 5 | //*Pre Processor directives 6 | #include 7 | #include 8 | //main function 9 | main() 10 | { 11 | //variable declarations 12 | double length = 0.0, area = 0.0, peri= 0.0, perift=0.0, periInch; 13 | printf("Side please in inches \n");//user prmpt; 14 | scanf_s("%lf", &lenght); // user input 15 | //process 16 | printf("You entered %.2lf:\n", lenght); 17 | //process 18 | area = length* length; 19 | printf("sides of the square is %.2lf square inches\n", area); 20 | printf("add all the sides of hte square is %.2lf inches\n", peri); 21 | perift = (int)peri / 12; 22 | periInch = (int)peri % 12; 23 | printf = ("\n\inPerimeter of square is .%i feet and %i inches\n" , perift, periInch); 24 | 25 | 26 | 27 | system("pause"); 28 | //end main 29 | } -------------------------------------------------------------------------------- /piggybank.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | Date:9/29/2016 3 | Specifications: How much in the piggy bank*/ 4 | 5 | 6 | #include 7 | #include 8 | 9 | //Main Funftion 10 | 11 | main() 12 | 13 | { 14 | //variables 15 | double hd = 0.5, q = 0.25, d = 0.1, n = 0.05, p = 0.01; 16 | double a1 = hd*0.5, a2 = q*0.25, a3 = d*0.1, a4 = n*0.05, a5 = p*0.01; 17 | 18 | printf("How many hd!\n");//user prompt 19 | scanf_s("%lf", &hd); 20 | a1 = hd*0.5; 21 | 22 | 23 | 24 | printf("How many q!\n"); 25 | scanf_s("%lf", &q); 26 | a2 = q*0.25; 27 | 28 | printf("How many d!\n"); 29 | scanf_s("%lf", &d); 30 | a3 = d*0.1; 31 | 32 | printf("How many n!\n"); 33 | scanf_s("%lf", &n); 34 | a4 = n*0.05; 35 | 36 | printf("How many p!\n"); 37 | scanf_s("%lf", &p); 38 | a5 = p*0.01; 39 | 40 | printf("Total is %.2lf\n", a1 + a2 + a3 + a4 + a5); 41 | 42 | 43 | system("pause"); 44 | }//end main 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /practiceOCT25.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | date 10/25/2016 3 | Specifications:in class work*/ 4 | 5 | #include 6 | #include 7 | main() { 8 | 9 | int num = 1, avg = 0; 10 | for (i = 1; avg <= 0; i++) { 11 | printf("enter four numbers %i\n", num); 12 | sum = sum + avg; 13 | } 14 | system("pause"); 15 | } 16 | //end main -------------------------------------------------------------------------------- /practiceProblem1.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singofen 2 | date 10/17/2016 3 | specifications: practice problems, mixed arithmetic problems, double, int, 4 | modulous, and minus operators*/ 5 | 6 | #include 7 | #include 8 | 9 | main() 10 | 11 | { 12 | int a = 2, b = 4, c = 11, result; 13 | double d1 = 3.4, d2 = 1.7, doubleResult; 14 | 15 | result = a + c / b; 16 | printf("a + c / b = %i\n", result); 17 | 18 | result = (a + c) / b; 19 | printf_s("(a + c) / b = %i\n", result); 20 | 21 | result = (b * a) + c / a; 22 | printf(" (b * a) + c / a = %i\n", result); 23 | 24 | result = (int)d1 + (int)d2; 25 | printf("(int)d1 + (int)d2 = %i\n", result); 26 | 27 | result = (int)(d1 + d2); 28 | printf("(int)(d1 + d2) = %i\n", result); 29 | 30 | doubleResult = c / b + 6; 31 | printf("c / b + 6 = %lf\n", doubleResult); 32 | 33 | doubleResult = (double)c / b + a; 34 | printf("(double)c / b + a = %lf\n", doubleResult); 35 | 36 | doubleResult = d1 + d2 * a; 37 | printf("d1 + d2 * a = %lf\n", doubleResult); 38 | 39 | doubleResult = (a + c) % a * d2; 40 | printf("(a + c) %% a * d2 = %lf\n", a + c % a * d2); 41 | 42 | doubleResult = a * -d2; 43 | printf("a * -d2 = %lf\n", a * -d2); 44 | 45 | 46 | system("pause"); 47 | } -------------------------------------------------------------------------------- /printAVGdiff4numbers.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | date 10/25/2016 3 | Specifications:Enter 4 numbers and print average of those numbers*/ 4 | 5 | #include 6 | #include 7 | main() { 8 | 9 | int i, j, k, l; 10 | printf("enter 1 number\n"); 11 | scanf_s("%i", &i); 12 | for (i = 0; i <= 4; i++) 13 | for (j = 0; j < 3; j++) 14 | printf("%i", j); 15 | { 16 | 17 | } 18 | 19 | { 20 | printf("enter 2 numbers\n");//only need 2 "for loops". triangle problem 21 | 22 | }/* 23 | for (k = 0; k < 2; k++) 24 | { 25 | printf("enter 3 numbers\n"); 26 | 27 | } 28 | 29 | for (l = 0; l < 1; l++) 30 | { 31 | printf("enter 4 numbers\n"); 32 | 33 | }*/ 34 | system("pause"); 35 | } 36 | //end main -------------------------------------------------------------------------------- /printAVGof4numbers.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | date 10/25/2016 3 | Specifications:Enter 4 numbers and print average of those numbers*/ 4 | 5 | #include 6 | #include 7 | main() { 8 | 9 | int i, j, k, l; 10 | 11 | for (i = 0; i < 4; i++) 12 | { 13 | printf("enter 1 number\n"); 14 | } 15 | 16 | for (j = 0; j< 3; j++) 17 | { 18 | printf("enter 2 numbers\n"); 19 | 20 | } 21 | for (k = 0; k < 2; k++) 22 | { 23 | printf("enter 3 numbers\n"); 24 | 25 | } 26 | 27 | for (l = 0; l < 1; l++) 28 | { 29 | printf("enter 4 numbers\n"); 30 | 31 | } 32 | system("pause"); 33 | } 34 | //end main -------------------------------------------------------------------------------- /problem3Function.c: -------------------------------------------------------------------------------- 1 | /*programmer chase 2 | instructions - write C program that allows the user 3 | to enter 3 grades from student and displays the average and 4 | percentage*/ 5 | 6 | #include 7 | #include 8 | 9 | double askPoints() { 10 | double grade; 11 | printf("input a grade\n"); 12 | scanf_s("%lf", &grade); 13 | return grade; 14 | 15 | } 16 | 17 | double avgPoints(double a, double b, double c) { 18 | 19 | double avg; 20 | avg = (a + b + c) / 3; 21 | return avg; 22 | 23 | 24 | } 25 | 26 | 27 | void display(double x, double y) {// not retuning any value (void) 28 | 29 | 30 | printf("the average is %.2lf, the percentage is%.2lf\n",x, y); 31 | 32 | } 33 | 34 | double percentPoints(double a, double b, double c) { 35 | 36 | double per; 37 | per = (a + b + c) / 3; 38 | return per; 39 | } 40 | main() { 41 | 42 | double num1, num2, num3, num4, num5; 43 | 44 | 45 | num1 = askPoints();//invoked each num or int 46 | num2 = askPoints(); 47 | num3 = askPoints(); 48 | 49 | num4 = avgPoints(num1, num2, num3);//passing by value. passing by variables all 3 arguments. 50 | num5 = percentPoints(num1, num2, num3); 51 | 52 | display(num4, num5); 53 | 54 | 55 | system("pause"); 56 | } 57 | -------------------------------------------------------------------------------- /radiusandcircumfrence.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | Date: 9/13/2016 3 | Specifications: Finding average grades*/ 4 | 5 | //*Pre Processor directives 6 | #include 7 | #include 8 | //main function 9 | main() 10 | { 11 | //variable declarations 12 | double r = 0, area = 0, c = 0; 13 | printf("Please enter radius\n");//user prmpt; 14 | scanf_s("%lf", &r); // user input 15 | //process 16 | area = 3.14 * r * r; 17 | c = 2 * 3.14 * r; 18 | //output 19 | printf("The area is : %.2lf square inches\n", area); 20 | printf("The circumference is :%.2lf inches\n", c); 21 | system("pause"); 22 | }//end main 23 | -------------------------------------------------------------------------------- /revisedhwdivisible.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | Date 10/18/16 3 | Specifications: Create a loop that will output 4 | the divisibles of 2 and 7. but less than 200. 5 | */ 6 | 7 | 8 | 9 | #include 10 | #include 11 | main() 12 | { 13 | int count = 0; 14 | for (count = ; count <= 10; count++) 15 | printf_s("%i", count); 16 | } 17 | system("pause"); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /sample 1 hw in class.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singhofen/c-programming/05d52ea8f7d2db896fac8c7c9923bdd5519b9b7c/sample 1 hw in class.c -------------------------------------------------------------------------------- /shipping.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | Date 10/5/2016 3 | Specifications:Shipping Calculations. 4 | */ 5 | //This program will calculate shipping charges based on miles and weight. 6 | //Packages less than or equal to 10lbs will cost $2.00 7 | //Packages more than 10lbs but less than or equal to 50lbs will cost $4.50 8 | //Packages over 50 pounds will not be shipped. 9 | // Shipping charges will be based on every 500 miles with no pro ration. 10 | 11 | #include 12 | #include 13 | 14 | main() 15 | { 16 | double packageWeight, packageDistance, packagePrice = 0, shippingCost; 17 | int segmentNum; 18 | printf("Enter the weight of the package:\n"); 19 | scanf_s("%lf", &packageWeight); 20 | printf("The weight you have entered is %.2lf\n", packageWeight); 21 | 22 | 23 | 24 | // A package that weighs less than 10lbs will cost $2 25 | if (packageWeight <= 10) 26 | packagePrice = 2.00; 27 | 28 | 29 | // A package that weighs less than or equal to 50lbs but more than 10lbs will cost $4.50 30 | 31 | else 32 | 33 | { 34 | if (packageWeight <= 50) 35 | packagePrice = 4.50; 36 | 37 | // Do not ship packages weighing more than 50lbs 38 | 39 | else 40 | printf("The package will not ship. \n"); 41 | } 42 | 43 | 44 | // Shipping cost the same for 200 miles 45 | //This is one 500 mile segment 46 | printf("How far are you sending the package? \n"); 47 | scanf_s("%lf", &packageDistance); 48 | printf("The distance you entered is %.2lf\n", packageDistance); 49 | 50 | segmentNum = packageDistance / 500; 51 | 52 | if ((int)packageDistance % 500 != 0) 53 | segmentNum = segmentNum + 1; 54 | shippingCost = packagePrice*segmentNum; 55 | 56 | 57 | //The shipping cost 58 | printf("The shipping cost is: %.2lf\n", shippingCost); 59 | 60 | 61 | 62 | system("pause"); 63 | 64 | } -------------------------------------------------------------------------------- /shortcutOperators.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | date 10/18/2016 3 | Specifications: shortcut operators*/ 4 | 5 | #include 6 | #include 7 | //main function 8 | main() 9 | { 10 | scanf_s("find the small of several integers"); 11 | int 2; 12 | 13 | 14 | 15 | system("pause"); 16 | 17 | } -------------------------------------------------------------------------------- /slide10_7Problems.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singofen 2 | date 10/17/2016 3 | specifications: practice problems, mixed arithmetic problems, double, int, 4 | modulous, and minus operators*/ 5 | 6 | #include 7 | #include 8 | 9 | main() 10 | 11 | { 12 | int a = 2, b = 4, c = 11, result; 13 | double d1 = 3.4, d2 = 1.7, doubleResult; 14 | 15 | result = a + c / b; 16 | printf("a + c / b = %i\n", result); 17 | 18 | result = (a + c) / b; 19 | printf_s("(a + c) / b = %i\n", result); 20 | 21 | result = (b * a) + c / a; 22 | printf(" (b * a) + c / a = %i\n", result); 23 | 24 | result = (int)d1 + (int)d2; 25 | printf("(int)d1 + (int)d2 = %i\n", result); 26 | 27 | result = (int)(d1 + d2); 28 | printf("(int)(d1 + d2) = %i\n", result); 29 | 30 | doubleResult = c / b + 6; 31 | printf("c / b + 6 = %lf\n", doubleResult); 32 | 33 | doubleResult = (double)c / b + a; 34 | printf("(double)c / b + a = %lf\n", doubleResult); 35 | 36 | doubleResult = d1 + d2 * a; 37 | printf("d1 + d2 * a = %lf\n", doubleResult); 38 | 39 | doubleResult = (a + c) % a * d2; 40 | printf("(a + c) %% a * d2 = %lf\n", a + c % a * d2); 41 | 42 | doubleResult = a * -d2; 43 | printf("a * -d2 = %lf\n", a * -d2); 44 | 45 | 46 | system("pause"); 47 | } -------------------------------------------------------------------------------- /structures.c: -------------------------------------------------------------------------------- 1 | /*Structures (also called structs) are a way to group several related variables into one place. 2 | Each variable in the structure is known as a member of the structure. 3 | Unlike an array, a structure can contain many different data types (int, float, char, etc.). 4 | specifications: get the student roll number,name and marks as input and display the grade of student according to the marks*/ 5 | 6 | #include 7 | struct student 8 | { 9 | int rollno; 10 | char name[50]; 11 | float marks; 12 | }; 13 | struct student s[3]; 14 | void main() 15 | { 16 | for(int i=0;i<3;i++){ 17 | printf("\nenter the student roll number:"); 18 | scanf("%d",&s[i].rollno); 19 | printf("enter the student name:"); 20 | scanf("%s",s[i].name); 21 | printf("enter the student marks (out of 100):"); 22 | scanf("%f",&s[i].marks); 23 | 24 | if(s[i].marks>90){ 25 | 26 | printf("\ngrade of student %s is S",s[i].name); 27 | 28 | } 29 | else if(s[i].marks>80&&s[i].marks<=90) 30 | { 31 | printf("\ngrade of student %s is A",s[i].name); 32 | } 33 | else if(s[i].marks>60&&s[i].marks<=80) 34 | { 35 | 36 | printf("\ngrade of student %s is B",s[i].name); 37 | 38 | } 39 | else if(s[i].marks>40&&s[i].marks<=60) 40 | { 41 | printf("\ngrade of student %s is C",s[i].name); 42 | 43 | } 44 | 45 | else if(s[i].marks<=40) 46 | { 47 | printf("\ngrade of student %s is F",s[i].name); 48 | 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /switchpractice.c: -------------------------------------------------------------------------------- 1 | /*programmer chase 2 | date 11/5/16 3 | specifications-switch problem. 1. Display the smallest number entered 4 | 2. Display the largest number entered 5 | 3. Display the sum of the five numbers entered 6 | 4. Display the average of the five numbers entered 7 | */ 8 | 9 | #include> 10 | #include> 11 | //main funtioin 12 | main() { 13 | 14 | //variable declarations 15 | int choice=0, highNum = 1, lowNum = 2, sum = 3, avg = 4; 16 | //should average number be double????? 17 | 18 | 19 | printf("enter 5 numbers\n");//use these numbers 18, 21, 17, 44, 9. 20 | scanf_s(" %i %i %i %i" "%i", &choice, &highNum, &lowNum, &sum, &avg); 21 | 22 | 23 | 24 | 25 | 26 | switch (choice=0) { 27 | 28 | 29 | 30 | case '1': 31 | printf("%i is highNum", highNum); 32 | break; 33 | 34 | case '3': 35 | printf("%i is sum", sum); 36 | break; 37 | 38 | case '2': 39 | printf("%i is lowNum", lowNum); 40 | break; 41 | 42 | case '4': 43 | printf("%i is avg", avg); 44 | break; 45 | 46 | default: 47 | printf("invalid number\n");//error messege here 48 | 49 | } 50 | printf("the smallest number is %i\n", lowNum); 51 | printf("the largest number is %i\n", highNum); 52 | printf("the sum of numbers is %i\n", sum); 53 | printf("the avg number is %.2lf\n", avg); 54 | 55 | 56 | system("pause"); 57 | } -------------------------------------------------------------------------------- /temp_conversion.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | Date 9/28/2016 3 | Specifications: Convert Fahrenheit to Celcius 4 | */ 5 | 6 | #include 7 | #include 8 | main() 9 | { 10 | 11 | float celsius, fahrenheit; 12 | 13 | // Reads temperature in Fahrenheit from user 14 | printf("Enter temperature in Fahrenheit: "); 15 | scanf_s("%f", &fahrenheit); 16 | 17 | // Converts fahrenheit to celsius 18 | celsius = (fahrenheit - 32) * 5 / 9; 19 | 20 | printf("\n%.2f Fahrenheit = %.2f Celsius", fahrenheit, celsius); 21 | 22 | 23 | system("pause"); 24 | } -------------------------------------------------------------------------------- /test.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | Date 10/8/16 3 | Specifications: Ask the user to enter test scores. 4 | When they have entered all the tests scores, 5 | they will enter the value of -1. The Program 6 | will sum up all the scores entered, and output sum. 7 | 70, 80, 90, -1. Expected 240*/ 8 | 9 | 10 | #include 11 | #include 12 | 13 | main() { 14 | 15 | int score, sum = 0, count = 0, grades = 0; 16 | printf("Enter a test score(-1 to quit):"); 17 | scanf_s("%i", &score); 18 | while (score != -1) { 19 | sum = sum + score; 20 | printf("Enter a test score(-1 to quit):"); 21 | scanf_s("%i", &score); 22 | 23 | } 24 | printf("\nThe sum of the scores is : %i\n", sum); 25 | 26 | { 27 | count = count + grades; 28 | 29 | 30 | if (score < 0 || score > 100); 31 | 32 | 33 | else { 34 | count = count + grades; 35 | 36 | 37 | if (score >= 70 && score <= 100); 38 | 39 | } 40 | 41 | 42 | 43 | } 44 | { 45 | 46 | 47 | 48 | } 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | system("pause"); 60 | 61 | } -------------------------------------------------------------------------------- /test1.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | Date 10/8/16 3 | Specifications: Ask the user to enter test scores. 4 | When they have entered all the tests scores, 5 | they will enter the value of -1. The Program 6 | will sum up all the scores entered, and output sum. 7 | 70, 80, 90, -1. Expected 240*/ 8 | 9 | 10 | #include 11 | #include 12 | 13 | main() { 14 | 15 | int score, sum = 0, count = 0, grades = 0, avg = 0; 16 | printf("Enter a test score(-1 to quit):"); 17 | scanf_s("%i", &score); 18 | while (score != -1) { 19 | sum = sum + score; 20 | printf("Enter a test score(-1 to quit):"); 21 | scanf_s("%i", &score); 22 | 23 | } 24 | printf("\nThe sum of the scores is : %i\n", sum); 25 | 26 | { 27 | printf("Do not count this grade as passing"); 28 | scanf_s("%i", &grades); 29 | if (score < 0 || score > 100); 30 | else ("Count this grade as passing"); 31 | count = count + grades; 32 | 33 | 34 | 35 | 36 | { 37 | printf("\nThe passing grades are : %i\n", grades); 38 | } 39 | { 40 | printf("Count this as passing grades"); 41 | scanf_s("%i", &count); 42 | if (score >= 70 && score <= 100); 43 | else ("Dont count grade as passing"); 44 | if (score < 0 || score > 100); 45 | grades = grades + passing; 46 | 47 | { 48 | 49 | printf("\nThe count of the scores is : %i\n", count); 50 | } 51 | 52 | } 53 | printf("What is average of valid grades"); 54 | scanf_s("%i", &avg); 55 | grades + sum + avg; 56 | { 57 | printf("\nThe avg of the scores is : %i\n", avg); 58 | } 59 | { 60 | } 61 | 62 | system("pause"); 63 | } -------------------------------------------------------------------------------- /testGradeScores.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | Date 10/8/16 3 | Specifications: Ask the user to enter test scores. 4 | When they have entered all the tests scores, 5 | they will enter the value of -1. The Program 6 | will sum up all the scores entered, and output sum. 7 | 70, 80, 90, -1. Expected 240*/ 8 | 9 | 10 | #include 11 | #include 12 | 13 | main() { 14 | 15 | int score, sum = 0; 16 | printf("Enter a test score(-1 to quit):"); 17 | scanf_s("%i", &score); 18 | while (score != -1) { 19 | sum = sum + score; 20 | printf("Enter a test score(-1 to quit):"); 21 | scanf_s("%i", &score); 22 | 23 | } 24 | printf("\nThe sum of the scores is : %i\n", sum); 25 | system("pause"); 26 | 27 | } -------------------------------------------------------------------------------- /threeprices.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | Date: 9/18/2016 3 | Specification: Three Prices*/ 4 | 5 | #include 6 | #include 7 | main() { 8 | //variable declarations 9 | double item1Price, item2Price, item3Price; 10 | double totalPrice, tax, grandTotal; 11 | 12 | // get the data from the user 13 | printf("Enter the first price:\n"); 14 | scanf_s("%lf", &item1Price); 15 | printf("You entered %.2lf\n", item1Price); 16 | printf("Enter the second price:\n"); 17 | scanf_s("%lf", &item2Price); 18 | printf("You entered %.2lf\n", item2Price); 19 | printf("Enter the thrid price:\n"); 20 | scanf_s("%lf", &item3Price); 21 | printf_s("You entered %.2lf\n", item3Price); 22 | 23 | //calculate the results 24 | totalPrice = item1Price + item2Price + item3Price; 25 | tax = totalPrice * 0.07; 26 | grandTotal = totalPrice + tax; 27 | 28 | //output the results 29 | printf("The total price is : %.2lf\n", totalPrice); 30 | printf("The tax is: %.2lf\n", tax); 31 | printf("The grand total is: %.2lf\n", grandTotal); 32 | 33 | 34 | 35 | 36 | 37 | 38 | system("pause"); 39 | } //end main -------------------------------------------------------------------------------- /updateArrayStudy.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singhofen/c-programming/05d52ea8f7d2db896fac8c7c9923bdd5519b9b7c/updateArrayStudy.c -------------------------------------------------------------------------------- /whileCountMultiples.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | Date: 10/11/2016 3 | Specifications: use while & count in program for repetition*/ 4 | 5 | #include 6 | #include 7 | 8 | main() 9 | { 10 | int count = 0 score= 0, n= 0 sum = 0;//counter variable 11 | 12 | { 13 | multiple = count * 10; 14 | printf("How many grades\n"); 15 | scanf_s("%i", &n); 16 | while (count < n); 17 | { 18 | printf("Enter the grade\n"); 19 | scanf_s("%i", &score); 20 | 21 | printf("\n\nYou entered %i\n\n", score); 22 | count = count + 1; 23 | 24 | }//end while 25 | printf("\n\nSum of grades is %i\n\n", score); 26 | avg = sum / n; 27 | 28 | } 29 | 30 | 31 | system("pause"); 32 | } 33 | -------------------------------------------------------------------------------- /while_loops.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofe 2 | Date 10/8/16 3 | Specifications: While-loops*/ 4 | 5 | #include 6 | #include 7 | 8 | main() { 9 | 10 | int count = 1; 11 | 12 | while (count <= 10) { 13 | printf("%i", count); 14 | count = count + 1; 15 | } 16 | 17 | system("pause"); 18 | 19 | } -------------------------------------------------------------------------------- /whileloops2.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | Date 10/8/16 3 | Specifications: While-loops*/ 4 | //output the multiples 5 less than 100 5 | 6 | 7 | #include 8 | #include 9 | 10 | main() { 11 | 12 | int count = 5; 13 | 14 | while (count < 100) { 15 | printf("%i", count); 16 | count = count + 5; 17 | } 18 | 19 | system("pause"); 20 | 21 | } -------------------------------------------------------------------------------- /whileloops3.c: -------------------------------------------------------------------------------- 1 | /*Programmer Chase Singhofen 2 | Date 10/8/16 3 | Specifications: While-loops*/ 4 | //output the even numbers in decending order from 70 to 50, inclusive. 5 | 6 | 7 | #include 8 | #include 9 | 10 | main() { 11 | 12 | int count = 70; 13 | 14 | while (count >= 50) { 15 | printf("%i", count); 16 | count = count - 2; 17 | } 18 | 19 | system("pause"); 20 | 21 | } --------------------------------------------------------------------------------