Virajsinh

B_PRM_15

Nov 3rd, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. #include<conio.h>
  2. #include<stdio.h>
  3.  
  4. struct student
  5. {
  6.     union student
  7.     {
  8.         char name[20];
  9.         int roll;
  10.     }ua;
  11.    
  12.     int marks;
  13. };
  14.  
  15. void main()
  16. {
  17.     struct student stud;
  18.     char choice;
  19.     clrscr();
  20.     printf("\n Enter Name ? Y or N");
  21.     fflush(stdin);
  22.     scanf("%c",&choice);
  23.     if(choice == 'y' || choice == 'Y')
  24.     {
  25.         printf("Enter Name : ");
  26.         fflush(stdin);
  27.         gets(stud.ua.name);
  28.     }
  29.    
  30.     else
  31.     {
  32.         printf("Roll No : ");
  33.         scanf("%d", &stud.ua.roll);
  34.     }
  35.    
  36.     printf("\n Enter Mark : ");
  37.     scanf("%d",&stud.marks);
  38.     if(choice == 'y' || choice == 'Y')
  39.     {
  40.         printf("\n Name : %s",stud.ua.name);
  41.     }
  42.     else
  43.     {
  44.         printf("\n Roll : %d",stud.ua.roll);
  45.     }
  46.     printf("Mark : %d",stud.marks);
  47.    
  48.     getch();
  49. }
Add Comment
Please, Sign In to add comment