Introduction
Teachers produce mark sheets every semester; this project automates one. It is a natural exercise in arrays — a 2D array holds every mark — and in producing clean, aligned output.
Problem statement
Objectives
- Store tabular data in two-dimensional arrays
- Compute per-row and per-column statistics
- Map percentages to grades with an if-else ladder
- Format a professional-looking report
Features
- Up to 60 students and 6 subjects
- Totals, percentages and grades (O, A, B, C, P, F)
- Class average and subject toppers
- Grade distribution histogram
Concepts demonstrated
- 2D arrays
- Nested loops
- if-else ladder
- Formatted output
System architecture
Three global arrays hold the data: names, subjects and the 2D marks. Input is read in nested loops (students × subjects). Report generation is a second pass that prints each row and accumulates the class percentage and grade counts; a third pass scans each column for the topper.
Folder structure
Complete source code
Makefile
What each file does
- src/main.c
- Data arrays,
grade_for, validated input viaread_int, and the three-pass report inmain. - Makefile
- Build automation:
makebuilds./app,make testruns the sample session and compares it with the expected output,make cleanremoves build files.
How to run it
Build
Run
Test against the expected output
Expected output
Generated by running the project with tests/sample-input.txt. Your output should match tests/expected-output.txt exactly.
4 3 Maths Physics C Asha 92 88 95 Ravi 67 72 58 Meera 81 79 90 Kiran 35 42 38
Testing
- Compare with
tests/expected-output.txt(4 students, 3 subjects). - Enter a mark of 105 and confirm the program reports it as invalid.
- Check by hand: Asha's 275/300 is 91.67%, grade O.
Common errors
Names longer than 23 characters are cut off
This is deliberate: %23s protects the 24-byte buffer. Increase NAME_LEN if you need longer names.
Garbage in the report
Make sure the number of students and subjects is read before the arrays are filled, and that every mark is read with %d.
Possible improvements
- Save and load the class from a CSV file
- Sort the report by percentage
- Support different maximum marks per subject
Additional challenges
- 1Print the rank of every student, handling ties.
- 2Calculate each subject's average and standard deviation.
- 3Highlight students who failed any single subject even if their overall grade is a pass.
Built and tested it yourself? Mark it to update your dashboard.