Beyrin

lab2_4

Jun 1st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4.  
  5. typedef struct {
  6. char name[10];
  7. char address[50];
  8. int day;
  9. int month;
  10. int year;
  11. } Delivery;
  12.  
  13. void input(Delivery *P);
  14. void output(Delivery *P);
  15.  
  16. int main()
  17. {
  18.      Delivery mass[6], *P, max;
  19.     P = mass;
  20.  
  21.     int k, i, j;
  22.     for (k=0; k<5; k++)
  23.     {
  24.         printf("%d Address:\n", k+1);
  25.         input(P);
  26.         P++;
  27.     }
  28.  
  29.     for(i=0; i<5; i++)
  30.     {
  31.         for(j=0; j<5; j++)
  32.         {
  33.             max = mass[j];
  34.             if(mass[j+1].year < max.year)
  35.             {
  36.                 mass[j]=mass[j+1];
  37.                 mass[j+1]=max;
  38.                 if(mass[j+1].month < max.month)
  39.                 {
  40.                 mass[j]=mass[j+1];
  41.                 mass[j+1]=max;
  42.                 }
  43.                 if(mass[j+1].day < max.day)
  44.                 {
  45.                 mass[j]=mass[j+1];
  46.                 mass[j+1]=max;
  47.  
  48.                 }
  49.             }
  50.  
  51.  
  52.         }
  53.     }
  54.     P = mass;
  55.     for(j=0; j<5; j++)
  56.     {
  57.         output(P);
  58.         P++;
  59.     }
  60.  
  61.  
  62.     return 0;
  63. }
  64.  
  65. void input(Delivery *P){
  66. printf("Enter the reciver's name: ");
  67. scanf("%s", P->name);
  68. printf("Enter the reciver's address: ");
  69. scanf("%s", P->address);
  70.  
  71. do
  72.     {
  73.     printf("Enter the delivery day: ");
  74.     scanf("%d", &P->day);
  75.     }
  76. while ((P->day < 0) ||(P->day > 31));
  77. do
  78.     {
  79.     printf("Enter the delivery month: ");
  80.     scanf("%d", &P->month);
  81.     }
  82. while (P->month < 0 || P->month > 12);
  83. do
  84.     {
  85.     printf("Enter the delivery year: ");
  86.     scanf("%d", &P->year);
  87.     }
  88. while (P->year < 0);
  89. printf("\n");
  90.  
  91.  
  92. }
  93.  
  94. void output(Delivery *P){
  95. printf("%s %s %d %d %d\n", P->name, P->address, P->day, P->month, P->year);
  96.  
  97. }
Add Comment
Please, Sign In to add comment