Example For Nested Structure and Array Within Structure.
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <conio.h> struct data { int day; int month; int year; }; struct student { char name [20]; struct data bday ; struct data graduation_data; int grade[3]; }; int main () { int num , i , j; char f_name[10] , s_name[10] ; struct student list [30]; printf("Enter Number Of Students : \n"); scanf("%d",&num); for (i=0;i<num;i++){ printf("Please Enter Student %d First Name : \n",i+1); scanf("%s",f_name); printf("Please Enter Student %d Second Name : \n",i+1); scanf("%s",s_name); strcpy(list[i].name,f_name); strcat(list[i].name," "); strcat(list[i].name,s_name); printf("Please Enter Student %d BirthDay Date: (day/month/year)\n",i+1); scanf("%d%d%d",&list[i].bday.day,&list[i].bday.month,&list[i].bday.year); printf("Please Enter Student %d Graduation Date: (day/month/year)\n",i+1); scanf("%d%d%d",&list[i].graduation_data.day,&list[i].graduation_data.month,&list[i].graduation_data.year); printf("Please Enter Three Subject Grade For Student %d :\n",i+1); for (j=0;j<3;j++){ scanf("%d",&list[i].grade[j]); } } printf("Entered Student Information :\n \n"); for (i=0;i<num;i++){ printf("Student %d Name : %s\n",i+1,list[i].name); printf("Student %d BirthDay Date: %d / %d / %d \n",i+1,list[i].bday.year, list[i].bday.month,list[i].bday.day); printf("Student %d Graduation Date: %d / %d / %d \n",i+1,list[i].graduation_data.year, list[i].graduation_data.month,list[i].graduation_data.day); printf("Student %d Three Subjects Grades : \nSubject 1 Grade: %d\nSubject 2 Grade : %d\nSubject 3 Grade : %d\n" ,i+1,list[i].grade[0],list[i].grade[1],list[i].grade[2]); printf("\n"); } return 0 ; }
0 Comment to "Nested Structure and Array Within Structure."
Post a Comment