Click Here to see the problem detail.

Solution

Read the problem carefully & see source code.

Source Code
	
#include<stdio.h>
 
int main()
{
   int N,temp,n[1000],i,j,count,flag;
 
    while(scanf("%d",&N)!=EOF)
    {
    i=0;
         flag=1;
      while(i<N)
      {
          scanf("%d",&n[i]);
        i++;
       }
       j=1;
       count=0;
       while(flag)
       {
        flag=0;
        for(i=0;i<N-j;i++)
         {
            if(n[i]>n[i+1])
             {
             temp=n[i];
             n[i]=n[i+1];
             n[i+1]=temp;
             flag=1;
             count++;
             }
 
           }
          j++;
        }
      printf("Minimum exchange operations : %d\n",count);
       }
     return 0;
}

 


Next Previous