Use an integer called mode. When mode equals one, display your name. If the mode is two, then display your department. This mode variable needs to be declared as a member of the union. Write a C program:
Use the following union
union integer
{
int mode;
};
Sample Input and Output:
Enter your name
Mukesh
Enter your department
CSE
Enter integer mode
1
The mode says Mukesh
Implementation of above problem:
#include<stdio.h>
union integer
{
int mode;
};
union integer i;
int main()
{
char name[100],dep[100];
printf("Enter your name\n");
scanf("%s",name);
printf("Enter your department\n");
scanf("%s",dep);
printf("Enter integer mode\n");
scanf("%d",&i.mode);
if(i.mode==1)
printf("The mode says %s\n",name);
else
printf("The mode says %s\n",dep);
return 0;
}
Thanks
Mukesh Rajput
Post A Comment:
0 comments: