Advertisement
Sabbir-bin

structure type

Feb 15th, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4.  struct nametype{
  5.  char first[40];
  6.  char last[40];
  7.  
  8.  };
  9.  
  10.  struct studenttype{
  11.   int id;
  12.  
  13.   struct nametype name;
  14.  };
  15.  
  16.  int main()
  17.  {
  18.    struct studenttype student[3];
  19.    int i, n = 3;
  20.  
  21.    for(i=0; i<n; i++)
  22.    {
  23.       printf("\nEnter your student id %d: ", i+1);
  24.       scanf("%d",&student[i].id);
  25.  
  26.       printf("\nEnter your first name %d:", i+1);
  27.       scanf("%s", student[i].name.first);
  28.  
  29.       printf("\nEnter your last name %d:", i+1);
  30.       scanf("%s", student[i].name.last);
  31.    }
  32.    for(i=0; i<n; i++)
  33.    {
  34.      printf("\nID: %d\n", student[i].id );
  35.      printf("Name: %s %s\n", student[i].name.first, student[i].name.last);
  36.    }
  37.    return 0;
  38.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement