CoolInterview.com - World's Largest Collection of Interview Questions GET FREE MAGAZINE FROM SAP NOW!
Home| Ask Questions| About Us| Feedback| Contact Us|
 Interview Questions  
 Our Services  

Get 9,000 Interview Questions & Answers in an eBook.


  • 9500+ Pages
  • 9000 Question & Answers
  • All Tech. Categories
  • 14 MB Content

    Get it now !!



    Send your Resume to 6000 Companies

  • COOLINTERVIEW.COM LANGUAGES C DETAILS



    Question :
    Write a pro gramme to show bubble sort on a set of 10 numbers?

     Posted by: pratyaksh    Date: 8/17/2008

    Contact Author  Contact Author


    Answer :
    #include<stido.h>
    #include<conio.h>
    main()
    {
    int a[10],i;
    printf("Enter n");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    buuble_sort(a,n);
    for(i=0;i<n;i++)
    printf("%4d",a[i]);
    }
    void buuble_sort(int a[],int n)
    {
    int i,j, temp;
    for(i=1;i<=n-1;i++)
    for(j=0;j<n-i;j++)
    {
    if(a[j]>a[j+1])
    {
    temp=a[j];
    a[j]=a[j+1];
    a[j+1]=temp;
    }
    }
    }

     Posted by: anilkumar    

    Contact Author  Contact Author
    #include <stdio.h>
    #include <conio.h>
    void main()
    { int a[10];
    int i,j,k;
    clrscr();
    for(i=0;i<10;i++)
    { j=i+1;
    printf("
    Enter the %d element",j);
    scanf("\%d",&a[i]);
    }
    for(i=0;i<9;i++)
    {if (a[i]>a[i+1])
    k=a[i];
    a[i]=a[i+1];
    a[i+1]=k;
    }
    printf("
    The sorted elements are
    ");
    for(i=0;i<10;i++)
    printf("%d ",a[i]);
    }

     Posted by: Pranjal Gururani    

    Contact Author  Contact Author
    #include <stdio.h>
    #include <conio.h>
    void main()
    { int a[10];
    int i,j,k,t;
    clrscr();
    for(i=0;i<10;i++)
    { j=i+1;
    printf("Enter the %d element",j);
    scanf("%d",&a[i]);
    }
    for(i=0;i<9;i++)

    if(a[i]>a[i+1])
    {j=i+1;
    printf("
    Bubble sorting......
    ");

    for(t=0;t<10;t++)
    printf("%d ",a[t]);

    printf("
    The %d element need to be sorted
    ",j);

    k=a[i];
    a[i]=a[i+1];
    a[i+1]=k;
    printf("
    After sorting.......
    ");

    for(t=0;t<10;t++)
    printf("%d ",a[t]);
    }
    printf("
    AFTER FINAL SORTING ELEMENTS ARE:
    ");

    for(i=0;i<10;i++)
    printf("%d ",a[t]);
    getch();
    }

     Posted by: Pranjal Gururani    

    Contact Author  Contact Author
    A Better one.....

    #include <stdio.h>
    #include <conio.h>
    void main()
    { int a[10];
    int i,j,k,t;
    clrscr();
    for(i=0;i<10;i++)
    { j=i+1;
    printf("Enter the %d element",j);
    scanf("%d",&a[i]);
    }
    for(i=0;i<9;i++)

    if(a[i]>a[i+1])
    {j=i+1;
    printf("
    Bubble sorting......
    ");

    for(t=0;t<10;t++)
    printf("%d ",a[t]);

    printf("
    The %d element need to be sorted
    ",j);

    k=a[i];
    a[i]=a[i+1];
    a[i+1]=k;
    printf("
    After sorting.......
    ");

    for(t=0;t<10;t++)
    printf("%d ",a[t]);
    }
    printf("
    AFTER FINAL SORTING ELEMENTS ARE:
    ");

    for(i=0;i<10;i++)
    printf("%d ",a[i]);
    getch();
    }

     Posted by: Pranjal Gururani    

    Contact Author  Contact Author
    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int i,j,a[]={10,25,12,20,24,30,45,80,5,9},temp;
    clrscr();
    for(i=0;i<9;i++)
    {
    for(j=0;j<9;j++)
    {
    if(a[j]>a[j+1])
    {
    temp=a[j];
    a[j]=a[j+1];
    a[j+1]=temp;
    }
    }
    }
    for(i=0;i<10;i++)
    {
    printf("%d",a[i]);
    }
    getch();
    }

     Posted by: sujit kumar rout    

    Contact Author  Contact Author

    © CoolInterview.com
    Today's Special: Get Free Magazine from SAP now!

    A D V E R T I S E M E N T






    If you have the better answer, then send it to us. We will display your answer after the approval.
    Name :*
    Email Id :*
    Answer :*
    Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
    Process Verification  Enter the above shown code:*
    Inform me about updated answers to this question

       


    Rate the above answer. Help us to know about the answer.
    Category C Interview Questions
    Rating (0.0) By 0 users
    Added 8/17/2008
    Views 308
    Rate it!
    Free Offers 300 Free Magazines for you. No credit card required. No Shipping Charges. Absolutely Free for 1 Year.

    Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.

    Notify me when better answer is posted!
    Email:



    View ALL C Interview Questions


    Sponsored Links  

    Google Search

    Google

    CoolInterview.com is a part of Vyom Network.
    Copyright ©2003-2008 Vyom Technosoft Pvt. Ltd., All Rights Reserved. Privacy Policy
    Page URL: http://www.coolinterview.com/interview/15834/Default.asp?cachecommand=bypass


    Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial

    1.05