#include<stdio.h>
int main()
{
int i, j, k = 0, temp, n;
while(scanf("%d", &n))
{
int anik[n];
for(i=0; i<n; i++)
{
scanf("%d", &anik[i]);
}
for(i=0; i<n; i++)
{
for(j=i+1; j<n; j++)
{
if(anik[i]>anik[j])
{
k++;
temp = anik[i];
anik[i] = anik[j];
anik[j] = temp;
}
}
}
for(i=0; i<n; i++)
{
printf("%d ", anik[i]);
}
printf("\nExchange operations : %d\n", k);
}
return 0;
}
int main()
{
int i, j, k = 0, temp, n;
while(scanf("%d", &n))
{
int anik[n];
for(i=0; i<n; i++)
{
scanf("%d", &anik[i]);
}
for(i=0; i<n; i++)
{
for(j=i+1; j<n; j++)
{
if(anik[i]>anik[j])
{
k++;
temp = anik[i];
anik[i] = anik[j];
anik[j] = temp;
}
}
}
for(i=0; i<n; i++)
{
printf("%d ", anik[i]);
}
printf("\nExchange operations : %d\n", k);
}
return 0;
}
Comments
Post a Comment