Skip to content

Commit 16e05ca

Browse files
c programming exercises
1 parent 5c6f3f3 commit 16e05ca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2806
-0
lines changed

ArrayStudy.c

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*Programmer:Chase Singhofen
2+
Date:
3+
Specification:Array's Introduction
4+
*/
5+
6+
//preprocessors
7+
#include <stdio.h>
8+
#include <stdlib.h>
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

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*Programmer: chase
2+
Date: 11/22/2016
3+
Specification: Assignment 10
4+
*/
5+
6+
//preprocess directives
7+
//standard libraries
8+
#include <stdio.h>
9+
#include <stdlib.h>
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

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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<stdio.h>>
10+
#include<stdlib.h>>
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+
}

Quiz 6.c

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*Programmers: Isaah Santos, Chase Singhofen, Brandt Barry
2+
Date: 12-1-16
3+
Specifications: Quiz 6*/
4+
#include<stdio.h>
5+
#include<stdlib.h>
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+
}

Switch (2)fromwill.c

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*Programmer-
2+
Date-
3+
Specafication- */
4+
//Preproccessor directives
5+
#include<stdio.h>
6+
#include<stdlib.h>
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+
}

0 commit comments

Comments
 (0)