C program for Displaying 'N' Student details in Tabular form (structure)

#include <stdio.h>

// Structure definition
struct Student {
    char name[50];
    int rollno;
    float cgpa;
};

int main() {
    int n, i;

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

    struct Student s[n]; // array of structures

    // Input
    for(i = 0; i < n; i++) {
        printf("\nStudent %d\n", i + 1);

        printf("Enter Name: ");
        scanf("%s", s[i].name); // only single-word names

        printf("Enter Roll No: ");
        scanf("%d", &s[i].rollno);

        printf("Enter CGPA: ");
        scanf("%f", &s[i].cgpa);
    }

    // Output table
    printf("\n*****************************\n");
    printf("*\tName\tRollNo\tCGPA\t*\n");
    printf("*****************************\n");

    for(i = 0; i < n; i++) {
        printf("*\t%s\t%d\t%.2f\t*\n",
               s[i].name, s[i].rollno, s[i].cgpa);
    }

    printf("*****************************\n");

    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