-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathQ23.c
45 lines (43 loc) · 1.24 KB
/
Q23.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
35
36
37
38
39
40
41
42
43
44
45
/* Program: 23
Write a C program to accept details of 'n' employee(eno, ename, salary) and
display the details of employee having highest salary. Use array of structure.
*/
#include <stdio.h>
struct employee
{
long int eno;
char name[30];
int salary;
};
int main()
{
int t, i, max, no = 0;
printf("How many employees do you want to enter details ?\n");
scanf("%d", &t);
struct employee e[t];
for (i = 0; i < t; i++)
{
printf("\n\t_____Enter details of employee_%d(eno,ename,salary)_______\n\n", i + 1);
printf("Enter em%d eno: ", i + 1);
scanf("%ld", &e[i].eno);
fflush(stdin);
printf("Enter em%d ename: ", i + 1);
gets(e[i].name);
printf("Enter em%d salary: ", i + 1);
scanf("%d", &e[i].salary);
}
max = e[0].salary;
for (i = 0; i < t; i++)
{
if (e[i].salary > max)
{
max = e[i].salary;
no = i;
}
}
printf("\n\temployee %d of highest salary\n\n", no + 1);
printf("eno: %ld\n", e[no].eno);
printf("ename: %s\n", e[no].name);
printf("salary: %d\n", e[no].salary);
return 0;
}