Develop a C program to declare a union which will contain the following data for an employee: Employee code (as character), Name (as character) age (as integer). The employee codes to be stored in this union are E01.
Code
#include <stdio.h>/*union declaration*/union employee{char code[10];char name[30];int age};int main(){/*declare union variable*/union employee E01, E02, E03;/*read employee details*/printf("\nEnter details for E01 :\n");printf("Code ?:");scanf("%s",&E01.code);printf("Name ?:");scanf("%s",&E01.name);printf("Age ?:");scanf("%d", &E01.age);printf("\nEnter details for E02 :\n");printf("Code ?:");scanf("%s",&E02.code);printf("Name ?:");scanf("%s",&E02.name);printf("Age ?:");scanf("%d", &E02.age);printf("\nEnter details for E03 :\n");printf("Code ?:");scanf("%s",&E03.code);printf("Name ?:");scanf("%s",&E03.name);printf("Age ?:");scanf("%d", &E03.age);printf("\nDeailts of E01\n");printf("Code: %s\n",E01.code);printf("Name: %s\n",E01.name);printf("Age: %d\n",E01.age);printf("\nDeailts of E02\n");printf("Code: %s\n",E02.code);printf("Name: %s\n",E02.name);printf("Age: %d\n",E02.age);printf("\nDeailts of E03\n");printf("Code: %s\n",E03.code);printf("Name: %s\n",E03.name);printf("Age: %d\n",E03.age);return 0;}
Output
0 Comments
Post a Comment