Значит, у меня есть программа, которая сортирует элементы в массиве. Пользователь вводит capacity и элементы в массиве, но элементы должны быть [0...100] Я, честно говоря, не могу понять, почему из-за цикла моя программа не работает. Насколько я понимаю, местоположение верное. Будьте добры, помогите.
#include <stdio.h>
int main()
{
int i, j, a, n, number[100];
printf("Enter the capacity of array. \n");
scanf("%d", &n);
printf("Enter the numbers. Should be strictly [1...100]: \n");
for (i = 0; i < n; ++i)
scanf("%d", &number[i]);
while (number[j] > 100 || number[j] < 0) {
break;
}
for (i = 0; i < n; ++i)
{
for (j = i + 1; j < n; ++j)
{
}
if (number[i] > number[j])
{
a = number[i];
number[i] = number[j];
number[j] = a;
}
}
}
printf("The numbers arranged in ascending order are given below: \n");
for (i = 0; i < n; ++i)
printf("%d\n", number[i]);
return 0;
}
Output:
Enter the capacity of array.
3
Enter the numbers. Should be strictly [1...100]:
66 77 89
exited, segmentation fault
или:
Enter the capacity of array.
3
Enter the numbers. Should be strictly [1...100]:
0
12
88
exited, segmentation fault