By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,045 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Whats the problem with this one???

P: n/a
#include<stdio.h>
#include<conio.h>
int main()
{
int arr[50];
int y,a,pass,hold;
printf("Enter # of Items: ");scanf("%d",&y);
for(a=1;a<=y;a++)
{
printf("Num %d: ",a);scanf("%d",&arr[y]);
}

for( pass = 1 ; pass <= y - 1 ; pass++ )
for( a=0 ; a <= y - 2 ; a++ )
if( arr [ a ] arr [ a + 2 ] )
{
hold = arr [ a ];
arr [ a ] = arr [ a + 1 ];
arr [a + 1] = hold;

}
printf("\nData Items In Ascending Order\n");
for(a = 0 ; a <= y - 1 ;a++)
printf(" %5d ", arr[ y ] );
printf("\n");
getch();
}
bubble sort my every inputs

Sep 21 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
S S

Dating Ninja wrote:
#include<stdio.h>
#include<conio.h>
int main()
{
int arr[50];
int y,a,pass,hold;
printf("Enter # of Items: ");scanf("%d",&y);
for(a=1;a<=y;a++)
{
printf("Num %d: ",a);scanf("%d",&arr[y]);
replace &arr[y] by &arr[a-1]
}

for( pass = 1 ; pass <= y - 1 ; pass++ )
for( a=0 ; a <= y - 2 ; a++ )
if( arr [ a ] arr [ a + 2 ] )
{
hold = arr [ a ];
arr [ a ] = arr [ a + 1 ];
arr [a + 1] = hold;

}
printf("\nData Items In Ascending Order\n");
for(a = 0 ; a <= y - 1 ;a++)
printf(" %5d ", arr[ y ] );
arr[a]
printf("\n");
getch();
}
bubble sort my every inputs
besides the code will not work, you should know the algorithm before
implementation.

here is the correct code
#include<stdio.h>
int main()
{
int arr[50];
int y,a,pass,hold;
printf("Enter # of Items: ");scanf("%d",&y);
for(a=0;a<y;a++)
{
printf("Num %d: ",a+1);scanf("%d",&arr[a]);
}

for( pass = y-1 ; pass 0 ; pass-- )
for( a=0 ; a < pass ; a++ )
if( arr [ a ] arr [ a + 1 ] )
{
hold = arr [ a ];
arr [ a ] = arr [ a + 1 ];
arr [a + 1] = hold;

}
printf("\nData Items In Ascending Order\n");
for(a = 0 ; a <= y - 1 ;a++)
printf(" %5d ", arr[ a ] );
printf("\n");

}

Sep 21 '06 #2

P: n/a

"Dating Ninja" <mo********@yahoo.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...

You already got someone to answer you, but for future reference, please read
the FAQ at http://www.parashift.com/c++-faq-lite/, especially section 5.
(The whole thing is a great reference, really.)

Posting "what's the problem with this?" in the subject and then posting some
code in the message doesn't tell anyone what problem you're trying to
resolve. Are you getting compiler errors? Link errors? Run-time errors?
Are the results not what you expect? Are we supposed to guess what you're
trying to fix? Help us understand the problem, and you'll always get better
results here.

-Howard

Sep 21 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.