Whats the problem with this one???

Discussion in 'C++' started by Dating Ninja, Sep 21, 2006.

  1. Dating Ninja

    Dating Ninja Guest

    #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
    Dating Ninja, Sep 21, 2006
    #1
    1. Advertising

  2. Dating Ninja

    S S Guest

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

    }
    S S, Sep 21, 2006
    #2
    1. Advertising

  3. Dating Ninja

    Howard Guest

    "Dating Ninja" <> wrote in message
    news:...

    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
    Howard, Sep 21, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vaidas Gudas

    whats problem in asp.net 2.0

    Vaidas Gudas, Jan 9, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    4,501
    john smith
    Jan 9, 2006
  2. news.frontiernet.net
    Replies:
    6
    Views:
    1,092
    news.frontiernet.net
    Apr 16, 2004
  3. loveNUNO
    Replies:
    2
    Views:
    884
    loveNUNO
    Nov 20, 2003
  4. yogesh
    Replies:
    1
    Views:
    349
    Victor Bazarov
    Mar 14, 2007
  5. Merciadri Luca
    Replies:
    4
    Views:
    789
Loading...

Share This Page