The Gateway to Computer Science Excellence
0 votes
90 views

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

closed with the note: got ans
in Programming by Veteran (117k points)
closed by | 90 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 (609 points)
selected by
0
I havenot got. It is same in program2 too, na?? Then how program 2 running??
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
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,651 questions
56,214 answers
194,175 comments
95,433 users