in Programming in C closed by
437 views
0 votes
0 votes
closed with the note: got ans

Can someone tell me, why these two same program giving different output?Is there any problem in code or compiler not producing right?

Program1

Program2

in Programming in C closed by
by
437 views

1 Answer

1 vote
1 vote
Best answer
In your first program, you have done a silly mistake.

In that, you print the array after every pass. In the printing loop of an array, you have used "i" variable which is also used in your main for loop of bubble sort so after the first iteration of bubble sort i's value becomes 5 and because of that reason your main loop is terminated.

So whatever result you get in your first program is the only a result of bubble sort's first pass.
selected by

3 Comments

I havenot got. It is same in program2 too, na?? Then how program 2 running??
0
0
Look carefully in program2 your printing loop is after the bubble sort's main loop while in program1 your printing loop is inside the main loop and that loop is also using the i variable.
0
0
oh, yes. i loop working for 1 time

thanks :)
0
0

Related questions