This C program allows users to input the number of students, store student records as a structure in an array and print student information. In this C Program below we will store the student’s name, roll, age and CGPA and eventually print them.
Program:
#include <stdio.h>
#include <stdlib.h>
struct Student
{
char name[30];
long int roll;
int age;
float cgpa;
};
int main()
{
int n;
printf("Please enter the number of students: ");
scanf("%d", &n);
struct Student stuarr[n];
for(int i=0; i< n; i++)
{
printf("Please enter student %d's info: \n", i+1);
printf("Name: ");
scanf("%s", stuarr[i].name);
printf("Roll: ");
scanf("%ld", &stuarr[i].roll);
printf("Age: ");
scanf("%d", &stuarr[i].age);
printf("CGPA: ");
scanf("%f", &stuarr[i].cgpa);
printf("\n");
}
for(int i=0; i< n; i++)
{
printf("Student %d info: \n", i+1);
printf("Name: %s\n", stuarr[i].name);
printf("Roll: %ld\n", stuarr[i].roll);
printf("Age: %d\n", stuarr[i].age);
printf("CGPA: %f\n", stuarr[i].cgpa);
printf("\n");
}
return 0;
}
Output:
Leave a Reply