Write The program in Clanguage 1) Create a Structure named employee with name, i
ID: 3670203 • Letter: W
Question
Write The program in Clanguage
1) Create a Structure named employee with name, id, salary and department. Create two variables of employee type and assign values to the data members and then print all the data members. Write a sum() function which is going to take two structure variables and calculate the sum of salary of two employees. Print the sum of salary.
2) Change the above structure to union and then perform the above task
. 3) Print how many bytes are assigned for above structure and also the union?
4) Declare and initialize two character variables with values ‘d’ and ‘z’ and calculate the sum of these variables and explain whether it is implicit type casting or explicit type casting.
5) Pass two command line arguments { ‘Sam’, ‘John’} and print those two arguments onto the screen and print the total number of arguments and also what will be the first command line argument and print that first argument.
Explanation / Answer
#include<stdio.h>
struct employee
{
char name[30];
int id;
int salary;
char department[30];
};
sum(int salary1,int salary2)
{
printf(" Sum of salary of two employee : %d",(salary1+salary2));
}
int main()
{
struct employee emp1;
struct employee emp2;
printf("Enter Employee 1 details: ");
printf(" Enter Name : ");
scanf("%s",emp1.name);
printf("Enter Id : ");
scanf("%d",&emp1.id);
printf("Enter salary : ");
scanf("%d",&emp1.salary);
printf("Enter Department : ");
scanf("%s",emp1.department);
printf(" Enter Employee 2 details: ");
printf(" Enter Name : ");
scanf("%s",emp2.name);
printf("Enter Id : ");
scanf("%d",&emp2.id);
printf("Enter salary : ");
scanf("%d",&emp2.salary);
printf("Enter Department : ");
scanf("%s",emp2.department);
printf(" Employee 1 details : ");
printf(" Name : %s",emp1.name);
printf(" Id : %d",emp1.id);
printf(" Salary : %d",emp1.salary);
printf(" Department : %s",emp1.department);
printf(" Employee 2 details : ");
printf(" Name : %s",emp2.name);
printf(" Id : %d",emp2.id);
printf(" Salary : %d",emp2.salary);
printf(" Department : %s",emp2.department);
sum(emp1.salary,emp2.salary);
printf("Size of employee structure : %d",sizeof(employee));
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.