/* C program to accept Student Information (Rollno, Name, Percentage) and display same information using structure. */
#include<stdio.h>
struct StudentInfo
{ int Rno;
char Sname[20];
float Percentage;
}s1;
void main()
{ printf("\n Enter Student Information:");
printf("\n Student Roll number, Name, Percentage ");
scanf("%d",&s1.Rno);
scanf("%s",s1.Sname);
scanf(“%f",&s1.Percentage);
printf("\n Roll Number : %d",s1.Rno);
printf("\n Student Name : %s",s1.Sname);
printf("\n Percentage : %.2f",s1.Percentage);
}
A structure can contain an array as its member. In the StudentInfo structure, the structure contains a string which is an array of characters. If we wish to store the marks of 4 subjects of a student, the declaration will be:
struct StudentInfo
{ int Rno;
char Sname[20];
int marks[4];
float avg;
}s;
The members will be
s.Rno, s.Sname, s.marks[0]…s.marks[3], s.avg
Comments
Post a Comment
Please give us feedback through comments