How to prepare marks card in C – easy method
To create a marks card (report card) in C programming, you can structure the code to take input from the user, calculate the total and average of the marks, and display the result along with grades. Here’s an example of how you can do it:
c
#include <stdio.h> int main() { // Declare variables int i, numSubjects; float marks[10], total = 0.0, average; char name[50]; // Input student details printf("Enter student's name: "); gets(name); printf("Enter the number of subjects: "); scanf("%d", &numSubjects); // Input marks for each subject for (i = 0; i < numSubjects; i++) { printf("Enter marks for subject %d: ", i + 1); scanf("%f", &marks[i]); total += marks[i]; // Calculate total marks } // Calculate average average = total / numSubjects; // Output the marks card printf("\n------ Marks Card ------\n"); printf("Student Name: %s\n", name); printf("Total Marks: %.2f\n", total); printf("Average Marks: %.2f\n", average); // Assign grade based on average printf("Grade: "); if (average >= 90) printf("A+\n"); else if (average >= 80) printf("A\n"); else if (average >= 70) printf("B\n"); else if (average >= 60) printf("C\n"); else if (average >= 50) printf("D\n"); else printf("F\n"); return 0; }
Input: The program takes the student’s name, number of subjects, and marks for each subject.
Processing: It calculates the total and average marks.
Output: The student’s name, total marks, average, and the grade are displayed.
Grading system: You can adjust the grade boundaries based on the criteria you want.
Sample Output:
c
Enter student's name: RAGHU Enter the number of subjects: 3 Enter marks for subject 1: 85 Enter marks for subject 2: 90 Enter marks for subject 3: 78 ------ Marks Card ------ Student Name: RAGHU Total Marks: 253.00 Average Marks: 84.33 Grade: A
In this program, we’re simulating a simple marks card (report card) generator in C. Here’s a breakdown of the key components:
Variable Declaration
c
int i, numSubjects; float marks[10], total = 0.0, average; char name[50];
i
: Used as a loop counter.
numSubjects
: Stores the number of subjects for which marks will be entered.
marks[10]
: An array to hold the marks for each subject (with a maximum of 10 subjects).
total
: To accumulate the total marks of all subjects.
average
: To store the calculated average of the marks.
name[50]
: To store the student’s name (up to 50 characters).
Taking Input
c
printf("Enter student's name: "); gets(name); printf("Enter the number of subjects: "); scanf("%d", &numSubjects);
gets(name)
reads the student’s name.
scanf("%d", &numSubjects)
takes the number of subjects as input.
Loop for Entering Marks
c
for (i = 0; i < numSubjects; i++) { printf("Enter marks for subject %d: ", i + 1); scanf("%f", &marks[i]); total += marks[i]; // Add the entered mark to the total }
We loop through numSubjects
times to collect marks for each subject.
The marks are stored in the marks[]
array.
The total marks are updated with each entry.
Calculating the Average
c
average = total / numSubjects;
The total marks are divided by the number of subjects to get the average marks.
Displaying the Marks Card
c
printf("\n------ Marks Card ------\n"); printf("Student Name: %s\n", name); printf("Total Marks: %.2f\n", total); printf("Average Marks: %.2f\n", average);
The student's name, total marks, and average marks are displayed using printf()
.
Grading System
c
printf("Grade: "); if (average >= 90) printf("A+\n"); else if (average >= 80) printf("A\n"); else if (average >= 70) printf("B\n"); else if (average >= 60) printf("C\n"); else if (average >= 50) printf("D\n"); else printf("F\n");
Based on the average marks, the program assigns a grade:
A+
for averages 90 and above.A
for averages between 80 and 89.B
,C
,D
, andF
are similarly assigned for other ranges.
How the program works:
Input: The user is prompted to enter the student's name, the number of subjects, and marks for each subject.
Processing: The program calculates the total and average marks from the input. Then, based on the average, it assigns a grade.
Output: Finally, the marks card is printed with the total marks, average, and the grade.
Note: This program provides a simple structure for building a marks card system, and it can be expanded to include more features like handling multiple students, input validation, etc.
Popular post
-
Eclipse IDE – Create New Java Project.
Opening the New Java Project…
-
How to start the project in android studio
Android Studio Open the Android…
-
How to use ACOSH function in excel
The ACOSH function returns the…
-
Complete Header tags in html – easy to learn
H tags can be used…
-
Best features in Python programme – easy to learn
Python is the most widely…