0
6.9kviews
Create an array of structure to store the details of almost 100 employees. And sort it according to employee ID. Employee details are as follows:(i) Employee Name (ii) Employee (iii) Employee salary
1 Answer
written 8.1 years ago by | • modified 8.1 years ago |
Program:
#include<stdio.h>
#include<conio.h>
struct employee {
char name[20];
int salary, code;
};
int main() {
struct employee e[100], temp;
int i, j;
for(i=0; i<=99; i++) {
printf("Enter the Employee's Name, Code and Salary:");
scanf("%s %d %d", e[i].name,&e[i].code,&e[i].salary);
}
for(i=0; i<=98; i++) {
for(j=0; j<=98; j++) {
if(e[j].code>e[j+1].code) {
temp=e[j];
e[j]=e[j+1];
e[j+1]=temp;
}
}
}
printf("\nEmployee List:\nName\tCode\tSalary\n");
printf("-----------------------------------------------------\n");
for(i=0; i<=99; i++) {
printf("%s\t%d\t%d\n",e[i].name,e[i].code,e[i].salary);
}
getch();
}
Output:
Enter the Employee's Name, Code and Salary:
EDEN
01
50000
Enter the Employee's Name, Code and Salary:
OSCAR
02
40000
.
.
Enter the Employee's Name, Code and Salary:
PETER
100
50000