The Gateway to Computer Science Excellence
0 votes

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



closed with the note: got ans
in Programming by Veteran (119k points)
closed by | 96 views

1 Answer

+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.
by Junior (853 points)
selected by
I havenot got. It is same in program2 too, na?? Then how program 2 running??
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.
oh, yes. i loop working for 1 time

thanks :)
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,833 questions
57,689 answers
107,283 users