Develop a program in C using structure to ask the information of any 12 students with roll_number, name and marks scored in sub1, sub2, and sub3. Also, display them in proper format along with the calculation of total and percentage. [Note: the full marks of each subject is 100].

 #include <stdio.h>


struct Student {

    int roll_number;

    char name[50];

    int sub1, sub2, sub3;

    float total, percentage;

};


int main() {

    int i;

    struct Student s[12];


    // Ask for student information

    for (i = 0; i < 12; i++) {

        printf("\nEnter details of student %d:\n", i+1);

        printf("Roll number: ");

        scanf("%d", &s[i].roll_number);

        printf("Name: ");

        scanf("%s", &s[i].name);

        printf("Marks in subject 1: ");

        scanf("%d", &s[i].sub1);

        printf("Marks in subject 2: ");

        scanf("%d", &s[i].sub2);

        printf("Marks in subject 3: ");

        scanf("%d", &s[i].sub3);

        s[i].total = s[i].sub1 + s[i].sub2 + s[i].sub3;

        s[i].percentage = s[i].total / 3;

    }


    // Display student information

    printf("\n\nRoll No.\tName\t\tSub1\tSub2\tSub3\tTotal\tPercentage\n");

    for (i = 0; i < 12; i++) {

        printf("%d\t\t%s\t\t%d\t%d\t%d\t%.2f\t%.2f%%\n", s[i].roll_number, s[i].name, s[i].sub1, s[i].sub2, s[i].sub3, s[i].total, s[i].percentage);

    }


    return 0;

}


Netra Koirala

Netra Koirala

Computer Science Educator

Passionate computer science educator and author. Provides free study notes, practical guides, and tutorials for Class 9, 10, 11, 12, and B.Sc CSIT students in Nepal. Years of teaching experience in computer science fundamentals.

Computer Science notes, tutorials, MCQs, and educational resources for Nepal students. Covering Class 9, SEE preparation, Class 11, Class 12, SLC, programming, DBMS, networking, HTML, JavaScript, PHP, OOP and more.

Featured Post

Grade 10 Computer Science: Specification Grid & Model Questions

Specification Grid & Model Questions of Computer Science | Grade 10 📚 Examination Resource Specification Grid & M...

Followers