Advertisement
Shailrshah

Employee Database

Apr 20th, 2013
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.61 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. struct Employee
  5. {
  6.     int id;
  7.     char name[20];
  8.     int salary;
  9.     struct Date
  10.     {
  11.         int dd,mm,yyyy;
  12.     }d;
  13. }emp[50];
  14.  
  15. void swap(int *a,int *b)
  16. {
  17.     int temp;
  18.     temp=*a;
  19.     *a=*b;
  20.     *b=temp;
  21. }
  22.  
  23. int main()
  24. {
  25.     int n;      
  26.     int i,j;      
  27.     char t[20];
  28.    
  29.     printf("Enter the number of Employees:-\n");
  30.     scanf("%d",&n);
  31.     for(i=0;i<n;i++)
  32.     {
  33.         printf("\nEmployee No %d:-\n",(i+1));
  34.         printf("Enter ID, Name, Salary and Date Of Joining(dd mm yyyy):-\n");
  35.                                 scanf("%d%s%d%d%d%d",&emp[i].id,emp[i].name,&emp[i].salary,&emp[i].d.dd,&emp[i].d.mm,&emp[i].d.yyyy);
  36.     }
  37.    
  38.     //Sorting
  39.     for(i=0;i<(n-1);i++)
  40.     {
  41.         for(j=0;j<(n-1);j++)
  42.         {
  43.             if(emp[j].salary<emp[j+1].salary)
  44.             {
  45.                 swap(&emp[j].salary,&emp[j+1].salary);
  46.                 swap(&emp[j].id,&emp[j+1].id);
  47.                 swap(&emp[j].d.dd,&emp[j+1].d.dd);
  48.                 swap(&emp[j].d.mm,&emp[j+1].d.mm);
  49.                 swap(&emp[j].d.yyyy,&emp[j+1].d.yyyy);
  50.                
  51.                 strcpy(t,emp[j].name);
  52.                 strcpy(emp[j].name,emp[j+1].name);
  53.                 strcpy(emp[j+1].name,t);
  54.             }
  55.         }
  56.     }
  57.    
  58.     printf("\nID\tName\tSalary\tDay\tMonth\tYear\n");
  59.     for(i=0;i<n;i++)
  60.     {
  61.         printf("\n%d\t%s\t%d\t%d\t%d\t%d",emp[i].id,emp[i].name,emp[i].salary,emp[i].d.dd,emp[i].d.mm,emp[i].d.yyyy);
  62.     }
  63. }
  64. //Output
  65. //Enter the number of Employees:-
  66. //2
  67.  
  68. //Employee No 1:-
  69. //Enter ID, Name, Salary and Date Of Joining(dd mm yyyy):-
  70. //323
  71. //Shail
  72. //60000
  73. //10
  74. //12
  75. //2009
  76.  
  77. //Employee No 2:-
  78. //Enter ID, Name, Salary and Date Of Joining(dd mm yyyy):-
  79. //453
  80. //Rahul
  81. //40000
  82. //4
  83. //5
  84. //2012
  85.  
  86. //ID      Name    Salary  Day     Month   Year
  87.  
  88. //323     Shail   60000   10      12      2009
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement