Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //это 30
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int main(void)
- {
- srand(time(NULL));
- system("chcp 1251>nul");
- int first_amount, second_amount, i;
- float first_max = .0, second_max = .0, temp;
- int first_index_max, second_index_max;
- printf("Введите количество элементов в первом массиве: ");
- scanf("%d", &first_amount);
- printf("Введите количество элементов во втором массиве: ");
- scanf("%d", &second_amount);
- float first_array[first_amount];
- float second_array[second_amount];
- for (i = 0; i < first_amount; i++)
- {
- first_array[i] = (float)(rand() % 100) / (rand() % 10 + 1);
- printf("first_array[%d] = %.2f\n", i, first_array[i]);
- }
- printf("\n");
- for (i = 0; i < second_amount; i++)
- {
- second_array[i] = (float)(rand() % 100) / (rand() % 10 + 1);
- printf("second_array[%d] = %.2f\n", i, second_array[i]);
- }
- for (i = 0; i < first_amount; i++)
- {
- if (first_array[i] > first_max)
- {
- first_max = first_array[i];
- first_index_max = i;
- }
- }
- for (i = 0; i < second_amount; i++)
- {
- if (second_array[i] > second_max)
- {
- second_max = second_array[i];
- second_index_max = i;
- }
- }
- printf("\n1: first_array[%d] = %.2f\n\n", first_index_max, first_max);
- printf("2: second_array[%d] = %.2f\n\n", second_index_max, second_max);
- temp = first_array[first_index_max];
- first_array[first_index_max] = second_array[second_index_max];
- second_array[second_index_max] = temp;
- for (i = 0; i < first_amount; i++)
- printf("first_array[%d] = %.2f\n", i, first_array[i]);
- printf("\n");
- for (i = 0; i < second_amount; i++)
- printf("second_array[%d] = %.2f\n", i, second_array[i]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement