2/22/2009

C Program To Accept Employees Information And Display The Same Information Using Structure


/* C Program To Accept Employees Information And Display The Same Information Using Structure */
#include<stdio.h>
#include<conio.h>
struct employees
{
    int id,salary;
    char name[20],deptartment[20];
};
void main()
{
    struct employees emp[10];
    int i,n;
     printf("Enter the number of employees record:\n");
        scanf("%d", &n);
     printf("Enter the Employee information in the following format:\n");
     printf("-------------------------------------------------------\n");

    for(i=1;i<=n;i++)
    {
        printf("Enter the details of [%d] employee\n",i);
          printf("Employee ID:\n");
           scanf("%d",&emp[i].id);
          printf("Employee Name:\n");
           scanf("%s",&emp[i].name);
          printf("Salary:\n");
           scanf("%d",&emp[i].salary);
          printf("Department:\n");
           scanf("%s",&emp[i].deptartment);

    }
    printf("Employees details are as below:\n");
    printf("--------------------------------\n");
    printf("Employee ID\tName\t\tSalary\t\tDepartment \n");
    printf("-----------------------------------------------------------\n");
    for(i=1;i<=n;i++)
    {
        printf("%d\t\t%s\t\t%d($)\t%s\n",emp[i].id,emp[i].name,emp[i].salary,emp[i].deptartment);
    }

 }
Out Put:
Enter the number of employees record:
2
Enter the Employee information in the following format:
-------------------------------------------------------
Enter the details of [1] employee
Employee ID:
100
Employee Name:
Kamran
Salary:
65000
Department:
Management
Enter the details of [2] employee
Employee ID:
200
Employee Name:
Keyvan
Salary:
40000
Department:
Sales
Employees details are as below:
--------------------------------
Employee ID     Name            Salary          Department
-----------------------------------------------------------
100             Kamran          65000($)        Management
200             Keyvan          40000($)        Sales

No comments:

Post a Comment