Skip to content
doubtly

1 answer

Answer: define a structure with roll number, name and three marks, make an array of it, and read and print n records with loops.

#include <stdio.h>

struct student {
    int roll;
    char name[50];
    int marks[3];
};

int main() {
    struct student s[100];
    int n, i, j;

    printf("Enter number of students: ");
    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        printf("\nStudent %d\n", i + 1);
        printf("Roll number: ");
        scanf("%d", &s[i].roll);
        printf("Name: ");
        scanf("%49s", s[i].name);
        printf("Marks in 3 subjects: ");
        for (j = 0; j < 3; j++)
            scanf("%d", &s[i].marks[j]);
    }

    printf("\nRoll\tName\tSub1\tSub2\tSub3\n");
    for (i = 0; i < n; i++) {
        printf("%d\t%s", s[i].roll, s[i].name);
        for (j = 0; j < 3; j++)
            printf("\t%d", s[i].marks[j]);
        printf("\n");
    }
    return 0;
}

Explanation: struct student groups the related data of one student. s[100] is an array of structures (up to 100 students, n should not exceed this). Members are accessed with the dot operator, e.g. s[i].roll. The first loop reads the records and the second prints them as a table.

(%49s reads a single-word name; use fgets if names contain spaces.)

Doubtly AI · 24 Oct 2026 AI-verified · Oct 2026 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.