C Programming
Computer Programming

C Program using structure to Calculate age of student at admission time



C program to read information of student. It contains Name, Roll number, Birthday, admission date. Calculate age of student at the time of admission

\* C Program using structure to Calculate age of student at admission time *\

# include < stdio.h >
# include < conio.h >
struct   student
{

int roll_num ; char name[20] ; struct Date
{
      int D ;
      int M ;
      int Y ;
} bd, ad ;

} ;

int   main( )
{

int r ;
struct student a ;
printf("\n Enter Student Details\n" ) ;
printf("----------------------------------------------------\n" ) ;
printf(" Enter Roll-Number : ") ;
scanf("%d", &a.roll_num ) ;
printf(" Enter Name : " ) ;
scanf("%s",a.name ) ;
printf(" Enter Birth-Date : ") ;
scanf("%d-%d-%d", &a.bd.D, &a.bd.M, &a.bd.Y ) ;
printf(" Enter Admission-Date : ") ;
scanf("%d-%d-%d", &a.ad.D, &a.ad.M, &a.ad.Y) ;
r = a.ad.Y-a.bd.Y ;
printf("----------------------------------------------------\n") ;
printf("\n Approximate Age of Student at the Time of Admission\n") ;
printf("----------------------------------------------------\n") ;
printf("\t%d Years", r) ;
return 0 ;

}

Output of Program :

Output of C Program using structure to Calculate age of student at admission time