C# Program to Generate Marksheet of Student

A marksheet generation program is a practical application that calculates a student's total marks, percentage, and grade based on subject scores. This C# program demonstrates how to create a simple marksheet system using basic input/output operations, arithmetic calculations, and conditional logic.

Algorithm

The marksheet generation follows these steps

Step 1 Declare variables for student roll number, name, subject marks, total marks, and percentage.

Step 2 Accept input for student details and marks in each subject.

Step 3 Calculate total marks by summing all subject marks.

Step 4 Calculate percentage by dividing total marks by the number of subjects.

Step 5 Determine grade based on percentage using conditional statements.

Step 6 Display the complete marksheet with all calculated values.

Marksheet Generation Process Input Data Calculate Total Find Percentage Assign Grade Grade Distribution A+ (91-100) | A (80-90) | B+ (70-79) | B (60-69) C (40-59) | D (34-39) | F (?35)

Using Fixed Number of Subjects

This approach is suitable when the number of subjects is predetermined. The program accepts marks for five subjects and generates the marksheet

using System;

class MarksheetGenerator {
   static void Main(string[] args) {
      // Variables declaration for student data
      int rollnum, marksub1, marksub2, marksub3, marksub4, marksub5, totalmark;
      float stud_percent;
      string name;

      // Sample student data (no user input for online compiler)
      rollnum = 101;
      name = "John Smith";
      marksub1 = 85;
      marksub2 = 92;
      marksub3 = 78;
      marksub4 = 88;
      marksub5 = 90;

      Console.WriteLine("=== STUDENT MARKSHEET ===");
      Console.WriteLine("Roll Number: " + rollnum);
      Console.WriteLine("Name: " + name);
      Console.WriteLine();

      // Display individual subject marks
      Console.WriteLine("Subject Marks:");
      Console.WriteLine("Subject 1: " + marksub1);
      Console.WriteLine("Subject 2: " + marksub2);
      Console.WriteLine("Subject 3: " + marksub3);
      Console.WriteLine("Subject 4: " + marksub4);
      Console.WriteLine("Subject 5: " + marksub5);
      Console.WriteLine();

      // Calculate total marks and percentage
      totalmark = marksub1 + marksub2 + marksub3 + marksub4 + marksub5;
      stud_percent = totalmark / 5.0f;

      // Display results
      Console.WriteLine("RESULTS:");
      Console.WriteLine("Total Marks: " + totalmark + "/500");
      Console.WriteLine("Percentage: " + stud_percent.ToString("F2") + "%");

      // Determine and display grade
      string grade;
      if (stud_percent >= 91) {
         grade = "A+";
      }
      else if (stud_percent >= 80) {
         grade = "A";
      }
      else if (stud_percent >= 70) {
         grade = "B+";
      }
      else if (stud_percent >= 60) {
         grade = "B";
      }
      else if (stud_percent >= 40) {
         grade = "C";
      }
      else if (stud_percent >= 35) {
         grade = "D";
      }
      else {
         grade = "F";
      }

      Console.WriteLine("Grade: " + grade);
   }
}

The output of the above code is

=== STUDENT MARKSHEET ===
Roll Number: 101
Name: John Smith

Subject Marks:
Subject 1: 85
Subject 2: 92
Subject 3: 78
Subject 4: 88
Subject 5: 90

RESULTS:
Total Marks: 433/500
Percentage: 86.60%
Grade: A

Using Dynamic Number of Subjects

This approach uses arrays to handle a variable number of subjects, making the program more flexible

using System;

class DynamicMarksheet {
   static void Main(string[] args) {
      // Variables declaration
      int rollnum, subnum, totalmark = 0;
      float stud_percent;
      string name;

      // Sample data (predefined for online compiler)
      rollnum = 102;
      name = "Alice Johnson";
      subnum = 4;
      int[] marksub = {88, 95, 82, 91}; // Sample marks for 4 subjects

      Console.WriteLine("=== DYNAMIC MARKSHEET ===");
      Console.WriteLine("Roll Number: " + rollnum);
      Console.WriteLine("Name: " + name);
      Console.WriteLine("Number of Subjects: " + subnum);
      Console.WriteLine();

      // Display marks and calculate total
      Console.WriteLine("Subject-wise Marks:");
      for (int i = 0; i = 91) grade = "A+";
      else if (stud_percent >= 80) grade = "A";
      else if (stud_percent >= 70) grade = "B+";
      else if (stud_percent >= 60) grade = "B";
      else if (stud_percent >= 40) grade = "C";
      else if (stud_percent >= 35) grade = "D";
      else grade = "F";

      Console.WriteLine("Grade: " + grade);
   }
}

The output of the above code is

=== DYNAMIC MARKSHEET ===
Roll Number: 102
Name: Alice Johnson
Number of Subjects: 4

Subject-wise Marks:
Subject 1: 88
Subject 2: 95
Subject 3: 82
Subject 4: 91

RESULTS:
Total Marks: 356/400
Percentage: 89.00%
Grade: A

Grade Classification System

Percentage Range Grade Performance Level
91% and above A+ Outstanding
80% - 90% A Excellent
70% - 79% B+ Very Good
60% - 69% B Good
40% - 59% C Average
35% - 39% D Below Average
Below 35% F Fail

Time Complexity Analysis

The fixed subjects approach has a time complexity of O(1) since it performs a constant number of operations regardless of input size.

The dynamic subjects approach has a time complexity of O(n) where n is the number of subjects, as it uses a loop to process each subject's marks.

Conclusion

This C# marksheet generation program demonstrates two approaches: fixed subjects for predetermined scenarios and dynamic arrays for flexible subject counts. Both methods effectively calculate totals, percentages, and assign grades based on performance criteria, making them suitable for educational management systems.

Updated on: 2026-03-17T07:04:36+05:30

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements