Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(C program) Create a struct to store the employee number, name, department, and

ID: 3870779 • Letter: #

Question


(C program) Create a struct to store the employee number, name, department, and salary. Create an array of employee structures and fill it with three sample employees. Then, write a function which, given an array of employees, will print the contents to standard output in a nice fashion. Make sure to use printf!
(C program) Create a struct to store the employee number, name, department, and salary. Create an array of employee structures and fill it with three sample employees. Then, write a function which, given an array of employees, will print the contents to standard output in a nice fashion. Make sure to use printf!
(C program)

Explanation / Answer

#include <stdio.h>
struct Employee {
int number;
char name[50];
char department[50];
double salary;
};
void printDetails(struct Employee *emp) {
int i;
printf("Number Name Department Salary ");
for(i=0;i<3;i++) {
printf("%d %s %s %lf ",emp[i].number,emp[i].name,emp[i].department,emp[i].salary);
}
}
int main()
{
int i;
struct Employee emp[3];
for(i=0;i<3;i++) {
printf("Enter the number: ");
scanf("%d", &emp[i].number);
printf("Enter the name: ");
scanf("%s", &emp[i].name);
printf("Enter the department: ");
scanf("%s", &emp[i].department);
printf("Enter the salary: ");
scanf("%d", &emp[i].salary);
}
printf(" ");
printDetails(emp);
return 0;
}

Output: