Skip to main content

Problem Statement

Write a C program that defines a structure to store a student’s name and marks, then takes input from the user and displays the stored information.

Solution

#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;
}

Input

Alice
92.5

Output

Name: Alice, Marks: 92.50