Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#include<stdio.

h>
#include<stdlib.h>
int movi(int a[],int m){
int i,j,key,c=0;

for(i=1;i<m;i++){
key=a[i];
j=i-1;
while(j>=0 && a[j]>key ){
a[j+1]=a[j];
j--;
c++;
}
a[j+1]=key;
}
return c;
}
int main(){
freopen("entrada.txt","r",stdin);
freopen("salida.txt","w",stdout);
freopen("entrada.txt","r",stdin);
freopen("salida.txt","w",stdout);
int c,i,a[1000],b[1000],j;
j=0;
while(scanf("%d",&c)==1){
i=0;
while(i<c){
scanf("%d",&a[i]);
i++;
}
b[j]=movi(a,i);
j++;
}

for(i=0;i<j;i++) printf("Minimum exchange operations : %d\n",b[i]);

system("pause");
return 0;
}

You might also like