Last active
May 3, 2017 16:36
-
-
Save skhozinova/f66d31a089ea43de2abc86a47e8fd8eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<stdlib.h> | |
#include<locale.h> | |
#include<string.h> | |
void insertion_sort(int *a,int t) | |
{ | |
int i,j,temp; | |
for (i=1;i<t;i++) | |
{ | |
temp=a[i]; | |
j=i-1; | |
while ((j>=0)&&(a[j]<temp)) | |
{ | |
a[j+1] =a[j]; | |
j--; | |
} | |
a[j+1]=temp; | |
} | |
} | |
int main (void)//с массивом | |
{ | |
int i=0,j=0,m=0,n=0,a[100][100],s[100],t=0; | |
setlocale(LC_ALL,"Russian"); | |
scanf("%d %d",&n,&m); | |
a[0][0]=3; | |
a[0][1]=10; | |
a[0][2]=67; | |
a[1][0]=34; | |
a[1][1]=53; | |
a[1][2]=89; | |
a[2][0]=15; | |
a[2][1]=27; | |
a[2][2]=41; | |
printf("Размерность матрицы:%d*%d\nНеотсортированный массив:\n",n,m); | |
for(i=0;i<n;i++) | |
{ | |
for(j=0;j<m;j++) | |
{ | |
printf("%d ",a[i][j]); | |
} | |
printf("\n"); | |
} | |
for(j=1;j<n-1;j++) | |
{ | |
for(i=0;i<n-j;i++) | |
{ | |
s[t]=a[i][i+j]; | |
t++; | |
} | |
insertion_sort(s,t); | |
t=0; | |
for(i=0;i<n-j;i++) | |
{ | |
a[i][j+i]=s[t]; | |
t++; | |
} | |
t=0; | |
} | |
printf("Oтсортированный массив:\n", insertion_sort(s,t)); | |
for(i=0;i<n;i++) | |
{ | |
for(j=0;j<m;j++) | |
{ | |
printf("%d ",a[i][j]); | |
} | |
printf("\n"); | |
} | |
system("pause"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment