Perform nested structure in C

Write a program to perform nested structure in C.


Source Code:

#include<stdio.h>
#include<conio.h>
struct date
{
	int dd,mm,yy;
};
struct student
{
	int en_no;
	struct date dob;
	int m1,m2,m3;
};
void main()
{
	struct student s1[3];
	int i;
	clrscr();
	for(i=0;i<3;i++)
	{
		printf("Enter the student no:");
		scanf("%d",&s1[i].en_no);
		printf("Enter the Date, month and year:");
		scanf("%d %d %d",&s1[i].dob.dd,&s1[i].dob.mm,&s1[i].dob.yy);
		printf("c");
		scanf("%d",&s1[i].m1);
		printf("Enter the Second subject mark:");
		scanf("%d",&s1[i].m2);
		printf("Enter the Third subject mark:");
		scanf("%d",&s1[i].m3);
	}
	printf("No  \t Date  \t Month \t Year \t M-1 \t M-2 \t M-3 \n ");
	for(i=0;i<3;i++)
	{
		printf("%d \t",s1[i].en_no);
		printf("%d \t",s1[i].dob.dd);
		printf("%d \t",s1[i].dob.mm);
		printf("%d \t",s1[i].dob.yy);
		printf("%d \t",s1[i].m1);
		printf("%d \t",s1[i].m2);
		printf("%d \t",s1[i].m3);
		printf("\n");
	}

	getch();
}

Output:

Enter the student no: 100
Enter the Date, month and year: 26 08 1993
Enter the First subject mark: 60
Enter the Second subject mark: 70
Enter the Third subject mark: 80

Enter the student no: 101
Enter the Date, month and year: 06 11 1988
Enter the First subject mark: 70
Enter the Second subject mark: 80
Enter the Third subject mark: 90

Enter the student no: 102
Enter the Date, month and year: 03 08 1992
Enter the First subject mark: 65
Enter the Second subject mark: 75
Enter the Third subject mark: 85

No	   Date        Month	       Year        M-1	         M-2	       M-3
100	   26	         08            1993        50             60           70
101        06            11            1988        70             80           90
102        03            08            1992        65             75           85

Leave a Reply

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