Program to declare a structure person (name, address) which contains another structure birthdate (day, month, year). Accept the details of n persons and display them.


C File =>


/* Write a program to declare a structure person (name, address) which contains another structure birthdate (day, month, year). Accept the details of n persons and display them. */


#include<stdio.h>
typedef struct Person
{
     char name[30];
     char addr[50];
     struct birth_date
    {
       int day;
       int month;
       int year;
     }b[100];
};
int main()
{
       struct Person p[100];
       int n,i;
       printf("\n Enter how many persons : ");
       scanf("%d",&n);
       for(i=0;i<n;i++)
      {
         printf("\n\n Enter name%d : ",i+1);
         scanf("%s",p[i].name);
         printf("\n Enter Address%d : ",i+1);
         scanf("%s",p[i].addr);
         printf("\n Enter birthdate(day month year)%d: ",i+1);
         scanf("%d%d%d",&p[i].b[i].day,&p[i].b[i].month,&p[i].b[i].year);
       }
       printf("\n\n Details of Person are :");
       for(i=0;i<n;i++)
      {
           printf("\n\n Name : %s",p[i].name);
           printf("\n Address : %s",p[i].addr);
           printf("\n Birth date : %d/%d/%d",p[i].b[i].day,p[i].b[i].month,p[i].b[i].year);
       }
return 0;
}

Comments

Popular posts from this blog

Write a program to allocate memory dynamically for n integers. Accept the elements and calculate their sum and average

C program to accept names of n cities and search for city named “Pune”.