Although the following assignments will not be graded, you are encouraged to complete them to prepare for the quizzes (which *will* be graded).
Homework 12 - n!
Write a recursive function that accepts an integer argument and returns its factorial.
Homework 11 - Order and link random numbers
Generate 100 random numbers and store them in memory in an orderly fashion. Print them out in order. You should use linked lists and C's random number generator.
afternoon session: http://ideone.com/0OtSsz
morning session: http://ideone.com/5jgUKL
afternoon session: http://ideone.com/0OtSsz
morning session: http://ideone.com/5jgUKL
Homework 10 - Calculate averages
A. You are a teacher, and you teach 5 different classes. Each class has a different number of students (e.g., 5, 8, 4, 7 and 5), which you store in a one-dimensional array of integers. You store the midterm exam scores (65, 99, 86, etc.) for each student in each class in a 2-dimensional array of integers. Write a program to calculate the average score for each class, storing them into an array of floats. Note that you will need to use typecasting.
B. You are a teacher, and you teach x classes. Write a program that accepts as input the number of classes x, dynamically allocates an array of size x, and inputs the number of students in each class. Don't forget to free the memory after you are finished using it.
http://ideone.com/8jp1Ml
B. You are a teacher, and you teach x classes. Write a program that accepts as input the number of classes x, dynamically allocates an array of size x, and inputs the number of students in each class. Don't forget to free the memory after you are finished using it.
http://ideone.com/8jp1Ml
Homework 9 - String search
Write a function searchString that searches for the string s2 in the string s1. If s2 is a substring of s1, return the index of the first occurrence. All of the character manipulation done by your functions must be done using the arrays passed into the functions as arguments. You may not define any additional arrays in your functions or globally.
Hint:
int searchString(char* s1, char* s2)
Examples:
searchString("abcabcdabcde", "bcd") - returns 4
searchString("abcabcdabcde", "xy") - returns -1
searchString("abcde", "") - returns 0
Hint:
int searchString(char* s1, char* s2)
Examples:
searchString("abcabcdabcde", "bcd") - returns 4
searchString("abcabcdabcde", "xy") - returns -1
searchString("abcde", "") - returns 0
Homework 8 - Chessboard array
Write a program that stores and prints out the pattern of an 8x8 chessboard automatically. Hint: I recommend that you use a 2D array of chars and assign the patterns using a nested for-loop.
Homework 7 - Struct for cars
A. Write a program that inputs and outputs the properties of a car. Use a struct to group the properties (color, brand, numWheels, numDoors, etc.)
B. What is the value of 10%4?
C. What is the difference between x=x+1, x+=1, x++, and ++x?
B. What is the value of 10%4?
C. What is the difference between x=x+1, x+=1, x++, and ++x?
Homework 6 - Playing with pointers
A. Complete Homework 4a using only pointers.
Homework 5 - Grade feedback
A. Write a program that accepts a letter grade as input and outputs the teacher's remarks. Use only switch, do not use any if's. Example: If 'A' or 'a', then "Excellent job!". If 'F' or 'f', then "You failed. Please study more next time."
B. What is the size of int -- how many bytes -- on your C compiler? What is the range of values you can store with int?
C. What is the size of unsigned int -- how many bytes -- on your C compiler? What is the range of values you can store with unsigned int?
D. What is the 8-bit 2's complement for -120?
B. What is the size of int -- how many bytes -- on your C compiler? What is the range of values you can store with int?
C. What is the size of unsigned int -- how many bytes -- on your C compiler? What is the range of values you can store with unsigned int?
D. What is the 8-bit 2's complement for -120?
Homework 4 - Make your own math functions
A. Make the four math functions below and test them in your main() function.
- Accepts two floats, returns the sum of the two
- Accepts two floats, returns the product of the two
- Accepts two floats, returns the minimum of the two
- Accepts two floats, returns the maximum of the two
Homework 3 - Count numbers with loops
Write a program to take as input three integers for (a) incrementing, (b) skipping and (c) ending. Your program should start counting from zero, incrementing by a, skip b and end at c. Write three versions of the program, each using a different looping mechanism, i.e. for loop, while loop and do-while loop.
Example 1:
input: 2, 6, 12
output: 0, 2, 4, 8, 10, 12
Example 2:
input: 3, 9, 15
output: 0, 3, 6, 12, 15
Example 1:
input: 2, 6, 12
output: 0, 2, 4, 8, 10, 12
Example 2:
input: 3, 9, 15
output: 0, 3, 6, 12, 15
Homework 2 - Class grade assignment
Write a program that takes as input a class score. Output the grade for the class based on the following guideline:
- Exactly 100 is A+
- 90 and above is A
- 80 and above is B
- 70 and above is C
- 60 and above is D
- Anything less than 60 is F
- Anything more than 100 or less than 0 is invalid input
Input
120 100 95.6 80 74.9 68.0 22.55 -90 |
Output
Class scores must each be between 0 and 100 A+ A B C D F Class scores must each be between 0 and 100 |
Homework 1 - Area of a rectangle
Write a program that accepts as input the lengths of the sides of a rectangle and outputs the area. Check your program using a C compiler, such as http://ideone.com/. If you need help with input/output, refer to this reference.