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
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: