[#include<stdio.h>
int main()
{
    int n, a, b, count,d,temp;
    int ara[1005];

    while(scanf("%d",&n) == 1){
        for(a = 0; a < n; a++){
            scanf("%d",&ara[a]);
        }
    count = 0;
        for(a = 0; a < n-1; a++){
            for(b = a + 1; b < n; b++){
                if(ara[b] < ara[a]){
                    temp = ara[a];
                    ara[a] = ara[b];
                    ara[b] = temp;
                    count++;
                }
            }
        }

            printf("\nMinimum exchange operations : %d\n",count);
    }
    return 0;
}][1]

asked 27 Aug '15, 19:42

piyush_mbstu's gravatar image

piyush_mbstu
317


In the problem they said , " only one operation (Flip) is available and that is you can exchange two adjacent terms" . So , basically ur inner loop is wrong . carefully observe that ur inner loop does not compare two adjacent terms . U have to compare adjacent terms only.

permanent link

answered 27 Aug '15, 22:38

Ahmad%20Musa's gravatar image

Ahmad Musa
563

Thanks vai, now accepted :)

(28 Aug '15, 04:11) piyush_mbstu

if you are satisfied , then please accept my answer :)

(28 Aug '15, 21:05) Ahmad Musa
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×14

question asked: 27 Aug '15, 19:42

question was seen: 1,069 times

last updated: 28 Aug '15, 21:05