Advertisement
Guest User

30

a guest
Feb 24th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.74 KB | None | 0 0
  1. //это 30
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5.  
  6. int main(void)
  7. {
  8.     srand(time(NULL));
  9.     system("chcp 1251>nul");
  10.     int first_amount, second_amount, i;
  11.     float first_max = .0, second_max = .0, temp;
  12.     int first_index_max, second_index_max;
  13.    
  14.     printf("Введите количество элементов в первом массиве: ");
  15.     scanf("%d", &first_amount);
  16.     printf("Введите количество элементов во втором массиве: ");
  17.     scanf("%d", &second_amount);
  18.    
  19.     float first_array[first_amount];
  20.     float second_array[second_amount];
  21.    
  22.     for (i = 0; i < first_amount; i++)
  23.     {
  24.         first_array[i] = (float)(rand() % 100) / (rand() % 10 + 1);
  25.         printf("first_array[%d] = %.2f\n", i, first_array[i]);
  26.     }
  27.     printf("\n");
  28.     for (i = 0; i < second_amount; i++)
  29.     {
  30.         second_array[i] = (float)(rand() % 100) / (rand() % 10 + 1);
  31.         printf("second_array[%d] = %.2f\n", i, second_array[i]);
  32.     }
  33.     for (i = 0; i < first_amount; i++)
  34.     {
  35.         if (first_array[i] > first_max)
  36.         {
  37.             first_max = first_array[i];
  38.             first_index_max = i;
  39.         }
  40.     }
  41.     for (i = 0; i < second_amount; i++)
  42.     {
  43.         if (second_array[i] > second_max)
  44.         {
  45.             second_max = second_array[i];
  46.             second_index_max = i;
  47.         }
  48.     }
  49.     printf("\n1: first_array[%d] = %.2f\n\n", first_index_max, first_max);
  50.     printf("2: second_array[%d] = %.2f\n\n", second_index_max, second_max);
  51.    
  52.     temp = first_array[first_index_max];
  53.     first_array[first_index_max] = second_array[second_index_max];
  54.     second_array[second_index_max] = temp;
  55.    
  56.     for (i = 0; i < first_amount; i++)
  57.         printf("first_array[%d] = %.2f\n", i, first_array[i]);
  58.    
  59.     printf("\n");
  60.    
  61.     for (i = 0; i < second_amount; i++)
  62.         printf("second_array[%d] = %.2f\n", i, second_array[i]);
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement