Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- void bubble_sort(int mas[], int N); // Сортировка пузырьком
- void print(int mas[], int N); // Вывод массива на экран
- void fill(int mas[], int N, int a, int b); // Заполнение массива случайными числами
- int main(){
- srand(time(0)); // Для генерации разных случайных чисел при каждом запуске программы
- unsigned const int SIZE = 20; // Размер массива
- int a[SIZE]; // Массив
- // Заполнение массива случайными числами
- fill(a, SIZE, -10, 10);
- // Печать изначального массива
- print(a, SIZE);
- // Сортировка массива
- bubble_sort(a, SIZE);
- // Печать измененного массива
- print(a, SIZE);
- return 0;
- }
- void bubble_sort(int mas[], int N){
- int i, j;
- for(i = 0; i < N-1; i++)
- for(j = i+1; j < N; j++)
- if (mas[i] < mas[j]){
- int temp = mas[i];
- mas[i] = mas[j];
- mas[j] = temp;
- }
- }
- void print(int mas[], int N){
- int i;
- for(i = 0; i < N; i++)
- printf("%d ", mas[i]);
- printf("\n");
- }
- void fill(int mas[], int N, int a, int b){
- int i;
- for(i = 0; i < N; i++)
- mas[i] = rand()%(b-a+1)+a;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement