Whats the problem with this one???

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dating Ninja

    Whats the problem with this one???

    #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

  • S S

    #2
    Re: Whats the problem with this one???


    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");

    }

    Comment

    • Howard

      #3
      Re: Whats the problem with this one???


      "Dating Ninja" <modkorewiz@yah oo.comwrote in message
      news:1158825193 .729145.145170@ h48g2000cwc.goo glegroups.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



      Comment

      Working...