C program for Structure

#include <stdio.h>

// Define a structure
struct Student {
    int roll;
    char name[50];
    float marks;
};

int main() {
    // Declare a structure variable
    struct Student s1;

    // Assign values
    printf("Enter Roll Number: ");
    scanf("%d", &s1.roll);

    printf("Enter Name: ");
    scanf("%s", s1.name);

    printf("Enter Marks: ");
    scanf("%f", &s1.marks);

    // Display values
    printf("\n--- Student Details ---\n");
    printf("Roll Number: %d\n", s1.roll);
    printf("Name: %s\n", s1.name);
    printf("Marks: %.2f\n", s1.marks);

    return 0;
}

Comments

Popular posts from this blog

Single Program Using All Automatic String Functions

C program for subtraction of two matrices (2D Arrays)

C program for Multiplication of Two matrices