C Program Example to Initialize Structure Variable

include

struct student
{
char name[50];
int roll;
float marks;
};
void main()
{
struct student s;
printf(“Enter information of students:\n\n”);
printf(“Enter name: “);
scanf(“%s”,s.name);
printf(“Enter Roll Number: “);
scanf(“%d”,&s.roll);
printf(“Enter Marks: “);
scanf(“%f”,&s.marks);
printf(“\nPrinting Entered Data: \n”);
printf(” Name: %s\n Roll Number: %d\n Marks: %.2f\n”,s.name,s.roll,s.marks);
getch();
}
OUTPUT:

Enter information of students:

Enter name: Lucky
Enter Roll Number: 538
Enter Marks: 98

Printing Entered Data:
Name: Lucky
Roll Number: 538
Marks: 98.00

Leave a Reply

Your email address will not be published. Required fields are marked *