Skip to main content

Q1. Student Record

Define a structure to store and display a student’s name and marks.
#include <stdio.h>

struct Student {
    char name[50];
    float marks;
};

int main() {
    struct Student s;
    printf("Enter name: ");
    scanf("%s", s.name);
    printf("Enter marks: ");
    scanf("%f", &s.marks);
    printf("Name: %s, Marks: %.2f\n", s.name, s.marks);
    return 0;
}

Q2. Array of Structures

Store records of 3 students and display them.
#include <stdio.h>

struct Student {
    char name[50];
    int roll;
};

int main() {
    struct Student s[3];
    for (int i = 0; i < 3; i++) {
        scanf("%s %d", s[i].name, &s[i].roll);
    }
    for (int i = 0; i < 3; i++) {
        printf("%s : %d\n", s[i].name, s[i].roll);
    }
    return 0;
}

Q3. Nested Structure

Use a nested structure to store a student’s date of birth.
#include <stdio.h>

struct Date {
    int day, month, year;
};

struct Student {
    char name[50];
    struct Date dob;
};

int main() {
    struct Student s = {"Alice", {15, 8, 2003}};
    printf("%s was born on %d/%d/%d\n",
        s.name, s.dob.day, s.dob.month, s.dob.year);
    return 0;
}