Thank you all for being with us.
Learn, Create and Implement.

  • Build Concept

    You can build your concept in programming on programsway.com.

  • Examples

    There are many C Programming examples on programsway.com.

  • Ask Questions

    Ask questions and get quick answers. Request any program and we will publish that program.

  • Wednesday, 12 March 2014



    #include<stdio.h>
    #include<stdlib.h>


    int *a,n;
    void bubblesort();
    void swap_w(int,int);


    main()
    {
    int i,j;
    printf("Enter the number of elements ");
    scanf("%d",&n);
    a=(int *)calloc(n,sizeof(int));
    printf("Enter the elements\n");
    for(i=0;i<n;i++)
    scanf("%d",a+i);
    bubblesort(0,n-1);
    printf("The sorted sequence is\n");
    for(i=0;i<n;i++)
    printf("%d ",a[i]);
    printf("\n");
    return;
    }


    void bubblesort()
    {
    int i,j;
    for(i=0;i<n-1;i++)
    for(j=n-1;j>=i+1;j--)
    if(a[j]<a[j-1])
    swap_w(j,j-1);
    }


    void swap_w(int i,int j)
    {
    int temp;
    temp=a[i];
    a[i]=a[j];
    a[j]=temp;
    return;
    }

    0 comments:

    Post a Comment