C (programming language)

C program to accept students marks and display result

This guide explores writing a C program to accept student marks for their subjects, calculate their total marks, percentage, and grade, and display the results. We’ll cover different aspects of the program in detail, making it easy for you to understand and implement it.

1. Program Structure

A typical C program accepting student marks involves:

  1. Header files: Including necessary header files like stdio.h for input-output and stdlib.h for various functions.
  2. Variable declaration: Declaring variables to store student information like name, marks in different subjects, total marks, percentage, and grade.
  3. User input: Accepting marks from the user for each subject using appropriate input functions like scanf.
  4. Calculations: Calculating the total marks by adding individual subject marks.
  5. Percentage calculation: Calculating the percentage by dividing the total marks by the maximum possible marks and multiplying by 100.
  6. Grade determination: Determining the grade based on the achieved percentage using conditional statements like if-else or lookup tables.
  7. Output: Displaying the student’s name, individual subject marks, total marks, percentage, and grade.

2. Example Code

Here’s an example C program demonstrating the functionalities mentioned above:


#include <stdio.h>

int main() {
  // Declare variables
  char name[50];
  float marks[5], total_marks, percentage, grade;

  // User input
  printf("Enter student name: ");
  scanf("%s", name);

  for (int i = 0; i < 5; i++) {
    printf("Enter marks for subject %d: ", i + 1);
    scanf("%f", &marks[i]);

  // Calculate total marks
  total_marks = 0;
  for (int i = 0; i < 5; i++) {
    total_marks += marks[i];

  // Calculate percentage
  percentage = (total_marks / 500) * 100;

  // Determine grade
  if (percentage >= 90) {
    grade = 'A';
  } else if (percentage >= 80) {
    grade = 'B';
  } else if (percentage >= 70) {
    grade = 'C';
  } else if (percentage >= 60) {
    grade = 'D';
  } else {
    grade = 'F';

  // Output
  printf("\nStudent: %s\n", name);
  printf("Marks in subject 1: %.2f\n", marks[0]);
  printf("Marks in subject 2: %.2f\n", marks[1]);
  printf("Marks in subject 3: %.2f\n", marks[2]);
  printf("Marks in subject 4: %.2f\n", marks[3]);
  printf("Marks in subject 5: %.2f\n", marks[4]);
  printf("Total Marks: %.2f\n", total_marks);
  printf("Percentage: %.2f%%\n", percentage);
  printf("Grade: %c\n", grade);

  return 0;

This program demonstrates accepting information for one student but can be easily modified to loop and process data for multiple students.

3. Enhancements and Modifications

Several features can be added to enhance the program:

  • Validation: Validate user input to ensure marks are within the correct range (e.g., 0-100).
  • Menu driven: Implement a menu to choose features like calculating results for another student, displaying averages for the class, etc.
  • Storing data: Use structures or arrays to store and manage information for multiple students.
  • Dynamic allocation: Allocate memory dynamically for arrays based on the number of subjects or students.
  • Read/Write data: Read student data from a file and write the results to a file.

These enhancements extend the program’s functionality and make it more robust and versatile.

4. Conclusion

This guide provides a starting point for writing a C program to accept student marks and display results. By understanding the core structure, calculations, and potential modifications, you can tailor the program to your specific needs and create a comprehensive tool for managing student assessments.

Remember to experiment, research further, and customize the program to meet your specific requirements. Good luck!


Learn coding the easy way. Find programming guides, examples and solutions with explanations.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button