Student result generation program in C

Here’s an example of a student result generation program in C:

#include <stdio.h>

int main() {
    char studentName[50];
    int marks[5];
    float totalMarks = 0, averageMarks;
    int i;

    // Input student name
    printf("Enter student name: ");
    fgets(studentName, sizeof(studentName), stdin);

    // Input marks for each subject
    printf("Enter marks for 5 subjects:\n");
    for (i = 0; i < 5; i++) {
        printf("Subject %d: ", i + 1);
        scanf("%d", &marks[i]);
        totalMarks += marks[i];
    }

    // Calculate average marks
    averageMarks = totalMarks / 5;

    // Display the student's result
    printf("\n----- Student Result -----\n");
    printf("Name: %s", studentName);
    printf("Average Marks: %.2f\n", averageMarks);

    if (averageMarks >= 60) {
        printf("Result: Passed\n");
    } else {
        printf("Result: Failed\n");
    }

    return 0;
}

To compile and run the program, follow these steps:

  1. Save the code in a file with a .c extension, such as result_generation.c.
  2. Open a terminal or command prompt and navigate to the directory where the file is saved.
  3. Compile the program using a C compiler (e.g., GCC) by running the following command:
    gcc -o result_generation result_generation.c
    This will create an executable file named result_generation.
  4. Run the program by executing the following command:
    ./result_generation

The program prompts the user to enter the student’s name and marks for five subjects. It then calculates the average marks and determines whether the student passed or failed based on the average score. Finally, it displays the student’s name, average marks, and the result on the screen.

Feel free to modify and enhance the program as per your specific requirements.