p14

Write a C program to define a union Contact that will contain the members Mobile no and E-mail id. Now define a structure Employee that will contain name, UID,PhNo, emailId and a variable of type Contact as members. The program will ask the user to give the details of five Employees including contact details. Print the details of all the Employees.


#include <stdio.h>
union job
{
   char name[32];
   float salary;
   int workerNo;
} job1;

int main()
{
   printf("Enter name:\n");
   scanf("%s", &job1.name);

   printf("Enter salary: \n");
   scanf("%f", &job1.salary);

   printf("Displaying\nName :%s\n", job1.name);
   printf("Salary: %.1f", job1.salary);

   return 0;
}
Output
Enter name 
Hillary
Enter salary
1234.23
Displaying
Name: f%Bary   
Salary: 1234.2

No comments:

Post a Comment