-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path13nov_2.c
36 lines (34 loc) · 983 Bytes
/
13nov_2.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
#include <stdio.h>
#include <stdlib.h>
struct employee {
int emp_id;
char name[50];
float salary;
};
int main() {
int n;
printf("Enter the number of employees: ");
scanf("%d", &n);
struct employee *employees = (struct employee *)malloc(n * sizeof(struct employee));
if (employees == NULL) {
printf("Memory allocation failed!\n");
return 1;
}
for (int i = 0; i < n; i++) {
printf("Enter details for employee %d:\n", i + 1);
printf("Employee ID: ");
scanf("%d", &employees[i].emp_id);
printf("Name: ");
scanf("%s", employees[i].name);
printf("Salary: ");
scanf("%f", &employees[i].salary);
}
printf("\nEmployee Details:\n");
for (int i = 0; i < n; i++) {
printf("Employee ID: %d\n", employees[i].emp_id);
printf("Name: %s\n", employees[i].name);
printf("Salary: %.2f\n", employees[i].salary);
}
free(employees);
return 0;
}