Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- struct Employee
- {
- int id;
- char name[20];
- int salary;
- struct Date
- {
- int dd,mm,yyyy;
- }d;
- }emp[50];
- void swap(int *a,int *b)
- {
- int temp;
- temp=*a;
- *a=*b;
- *b=temp;
- }
- int main()
- {
- int n;
- int i,j;
- char t[20];
- printf("Enter the number of Employees:-\n");
- scanf("%d",&n);
- for(i=0;i<n;i++)
- {
- printf("\nEmployee No %d:-\n",(i+1));
- printf("Enter ID, Name, Salary and Date Of Joining(dd mm yyyy):-\n");
- 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);
- }
- //Sorting
- for(i=0;i<(n-1);i++)
- {
- for(j=0;j<(n-1);j++)
- {
- if(emp[j].salary<emp[j+1].salary)
- {
- swap(&emp[j].salary,&emp[j+1].salary);
- swap(&emp[j].id,&emp[j+1].id);
- swap(&emp[j].d.dd,&emp[j+1].d.dd);
- swap(&emp[j].d.mm,&emp[j+1].d.mm);
- swap(&emp[j].d.yyyy,&emp[j+1].d.yyyy);
- strcpy(t,emp[j].name);
- strcpy(emp[j].name,emp[j+1].name);
- strcpy(emp[j+1].name,t);
- }
- }
- }
- printf("\nID\tName\tSalary\tDay\tMonth\tYear\n");
- for(i=0;i<n;i++)
- {
- 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);
- }
- }
- //Output
- //Enter the number of Employees:-
- //2
- //Employee No 1:-
- //Enter ID, Name, Salary and Date Of Joining(dd mm yyyy):-
- //323
- //Shail
- //60000
- //10
- //12
- //2009
- //Employee No 2:-
- //Enter ID, Name, Salary and Date Of Joining(dd mm yyyy):-
- //453
- //Rahul
- //40000
- //4
- //5
- //2012
- //ID Name Salary Day Month Year
- //323 Shail 60000 10 12 2009
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement