The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
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
asked in Programming by Veteran (111k points)
closed by | 76 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.
answered by Junior (549 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 :)

Related questions

0 votes
0 answers
asked Dec 8, 2018 in Programming by Na462 Loyal (6.6k points) | 95 views
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
49,540 questions
54,099 answers
71,006 users