-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathP-79.c
34 lines (34 loc) · 983 Bytes
/
P-79.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//Write a program in C to create a union.
#include <stdio.h>
int main()
{
int ch,rev;
union test {
long int ph; //for phone number
char email[50]; //for email id
}data;
printf("Enter :\n1. To enter phone number\n2. To enter email address \n");
scanf("%d",&ch);
if (ch==1)
{
printf("\nEnter phone number >> ");
scanf("%ld",&data.ph);
printf("\nDetails saved successfully !!!");
}
else if(ch==2)
{
printf("\nEnter email address >>");
scanf("%s",&data.email);
printf("\nDetails saved successfully !!!");
}
else
printf("WRONG CHOICE !!!");
printf("\nEnter 0 to view saved details , any other number to exit >> ");
scanf("%d",&rev);
if(rev==0) {
if (ch == 1)
printf("Entered phone number is %ld", data.ph);
else if (ch == 2)
printf("Entered email address is %s", data.email);
}
}