Write a C program to input roll, name and age of n no of students and display them properly using structure.

Question collected from Telegram Group
#include <stdio.h>
#include <string.h>

#define MAX_STUDENTS 100

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

int main() {
    int n, i;
    struct student students[MAX_STUDENTS];

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

    // Input student data
    for (i = 0; i < n; i++) {
        printf("Enter roll number for student %d: ", i+1);
        scanf("%d", &students[i].roll);

        printf("Enter name for student %d: ", i+1);
        scanf("%s", students[i].name);

        printf("Enter age for student %d: ", i+1);
        scanf("%d", &students[i].age);
    }

    // Display student data
    printf("\nStudent details:\n");
    for (i = 0; i < n; i++) {
        printf("Roll number: %d\n", students[i].roll);
        printf("Name: %s\n", students[i].name);
        printf("Age: %d\n", students[i].age);
        printf("\n");
    }

    return 0;
}

Output

Getting Info...

Post a Comment

Please do not enter any spam link in the comment box.
Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.