Define a
structure for the ‘n’ employees with the following fields:
emp_id(integer), emp_name(string),
emp_basic(float), emp_dest(string) and emp_age(integer).
Write the following function to process
the ‘n’ employees data:
i)Function to
read the ‘n’ employees data.
ii)Function to print the ‘n’ employees record.
#include<stdio.h>
struct
employee
{
int emp_id;
char emp_name[20];
float emp_basic;
char emp_dest[20];
int emp_age;
};
void read(struct employee e[10],
int n)
{
int i;
printf("\nEnter details of n
employees: ");
for(i=0;i<n;i++)
{
printf("\nEnter id
name basic des age of employee %d:::
", i+1);
scanf("%d %s %f %s %d", &e[i].emp_id, e[i].emp_name, &e[i].emp_basic,
e[i].emp_dest, &e[i].emp_age);
}
}
void display(struct employee
e[10], int n)
{
int i;
printf("\nDetails of n
employees: ");
for(i=0;i<n;i++)
{
printf("\nEmployee %d::
%d %s %f %s %d", i+1, e[i].emp_id, e[i].emp_name, e[i].emp_basic,
e[i].emp_dest, e[i].emp_age);
}
}
void
main()
{
int n;
struct employee emp[10];
printf("\nEnter the number of
employees: ");
scanf("%d",&n);
read(emp, n);
display(emp, n);
}
Output:
Enter the number of employees: 2
Enter details of n employees:
Enter
id name basic des age of employee 1:::
111 aaa 15000 manager 35
Enter
id name basic des age of employee 2:::
222 bbb 50000 director 60
Details of n employees:
Employee
1:: 111 aaa 15000.000000 manager 35
Employee
2:: 222 bbb 50000.000000 director 60
No comments:
Post a Comment