C program to read and display information of N students using an array of structure
Program:
#include<stdio.h>
struct student
{
char name[20];
int rollno;
float cpi;
};
void main( )
{
int i,n;
printf("Enter how many records u want to store : ");
scanf("%d",&n);
struct student sarr[n];
for(i=0; i<n; i++)
{
printf("\nEnter %d record : \n",i+1);
printf("Enter Name : ");
scanf("%s",sarr[i].name);
printf("Enter RollNo. : ");
scanf("%d",&sarr[i].rollno);
printf("Enter CPI : ");
scanf("%f",&sarr[i].cpi);
}
printf("\n\tName\t\tRollNo\t\tMarks\t\n");
for(i=0; i<n; i++)
{
printf("\t%s\t\t%d\t\t%.2f\t\n", sarr[i].name, sarr[i].rollno, sarr[i].cpi);
}
}
Output:
Enter how many records u want to store : 2
Enter 1 record :
Enter Name : Steve
Enter RollNo. : 10
Enter CPI : 9
Enter 2 record :
Enter Name : Peter
Enter RollNo. : 11
Enter CPI : 10
Name RollNo Marks
Steve 10 9.00
Peter 11 10.00
Drafted on 🌏 by,
Comments
Post a Comment