Answer the question
In order to leave comments, you need to log in
How to sort an array with random values?
I can’t figure out how to correctly write the code for sorting an array using the bubble method in C language, and how can I then display the sorted array on the screen
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int main(){
system("chcp 1251");
system("cls");
system("title Pr101");
system("Color F0");
int i, a, n, j, b, d;
int x[i];
int rand(void);
printf(" Количество элементов массива: ");
scanf("%d", &n);
if(n <= 0){
printf("Введите целое положительно число!");
return 0;
}
printf("\n Массив x \n");
for(d=0; d < n; d++)
x[i] = rand();
printf("%d", x[i]);
for(j=1; j<=n-1; j++){
for(i=0; i<=n-1-j; i++){
if(x[i]>x[i+1]){
b = x[i];
x[i] = x[i+1];
x[i+1] = b;
}
}
}
return 0;
}
Answer the question
In order to leave comments, you need to log in
Sorting doesn't work.
1. here:
int i, a, n, j, b, d;
int x[i];
for(d=0; d < n; d++)
x[i] = rand();
printf("%d", x[i]);
system("chcp 1251");
system("cls");
system("title Pr101");
system("Color F0");
for(d=0; d < n; d++)
x[i] = rand();
printf("%d", x[i]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question