Skip to content

Instantly share code, notes, and snippets.

@MaratB
Created September 22, 2013 22:00
Show Gist options
  • Save MaratB/6664291 to your computer and use it in GitHub Desktop.
Save MaratB/6664291 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <conio.h>
const int N = 10;
main()
{
int i, j, A[N], c;
for (i=0; i<N; i++) {
printf("Введите A[%i]: ", i);
scanf("%d", &A[i]);
}
for ( i = 0; i < N-1; i ++ ) // достаточно поставить N-1 элементов
for ( j = N-2; j >= i; j -- ) // идем с конца массива в начало
if ( A[j] > A[j+1] ) // если они стоят неправильно, ...
{
c = A[j]; A[j] = A[j+1]; // переставить A[j] и A[j+1]
A[j+1] = c;
}
printf("\n Отсортированный массив:\n");
for ( i = 0; i < N; i ++ )
printf("%d ", A[i]);
getch();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment