Array Assignment
Array Assignment
1. Write a C program that takes an integer array from the user as input, and prints the given array sorted.
- Input: { 5, 2, 9, 6, 2, 1, 7, 10 }
- Output: { 1, 2, 2, 5, 6, 7, 9, 10 }
2. Write a C program that takes an integer array from the user as input, and ask the user to enter the size of
the array, and find the following :
1. The sum of all elements of the array
2. The average value for the elements of the array
3. The minimum and the maximum element in the array
- Input: { 4, 3, 7, 10, 1, 9, 8, 2, 5, 6 }
- Output:
- Sum: 55
- Average: 5.5
- Minimum Value: 1
- Maximum Value: 10
3. Write a C program that takes an integer array from the user as input, and check if the array is sorted or
not.
- Input: { 4, 3, 7, 10, 1, 9, 8, 2, 5, 6 }
- Output: Not sorted
- Input: { 1, 2, 3, 4, 5 }
- Output: Sorted (Ascending)
- Input: { 5, 4, 3, 2, 1 }
- Output: Sorted (Descending)
4. Write a C program that takes an integer array from the user as input, and find the frequency of each
element.
- Input: { 4, 4, 1, 2, 6, 4, 5, 2, 5, 9, 8, 5 }
- Output:
- 4 appears 3 times
- 1 appears 1 time
- 2 appears 2 times
- 6 appears 1 time
- 5 appears 3 times
- 9 appears 1 time
- 8 appears 1 time
5. Write a C program that:
1. Asks the user to enter a 3x3 matrix.
2. Sort the array
3. Prints the sorted array
7. A professor wants to track the attendance of students throughout a 10-week semester. The professor will
enter the number of students in the class, and their attendance record will be stored in a row in a 2D integer
array, where:
1. Rows represent students’ names
2. Columns represent weekly attendance over 10 weeks
3. A value of 1 represents attendance, and a value of 0 represents absence.
4. Any invalid input (other than 0 or 1) must prompt the professor to re-enter a valid value.
Program requirements:
1. Ask the professor to enter the attendance for each student, one student at a time.
2. For each student, calculate:
1. Total attendance
2. Total absence
3. Attendance average - (total attendance / 10) * 100
3. Find the most and the least attended student
4. Calculate the average attendance percentage for the entire class. — (sum of total students attendance /
(total students * 10)) / 100
- Output:
---------------------------------------
ATTENDANCE SUMMARY
---------------------------------------
Alice - Attended: 7, Absent: 3, Attendance Percentage: 70.00%
Bob - Attended: 5, Absent: 5, Attendance Percentage: 50.00%
Charlie - Attended: 10, Absent: 0, Attendance Percentage: 100.00%
---------------------------------------
ATTENDANCE ANALYSIS
---------------------------------------
Most Attended Student: Charlie (100.00%)
Least Attended Student: Bob (50.00%)
Class Average Attendance: 73.33%