Bubblesort - C Program

Program:
#include<stdio.h>
//#include<conio.h>
void main()
{
    int a[100],i,j,n,t;
    printf("Enter the number of elements: ");
    scanf("%d",&n);
    printf("\nInput the elements\n");
    for(i=1;i<=n;i++)
    {
          scanf("%d",&a[i]);
    }
    for(i=1;i<n;i++)
    {
          for(j=1;j<=n-i;j++)
        {
             if(a[j]>a[j+1])
            {
                t=a[j];
                a[j]=a[j+1];
                a[j+1]=t;
            }
         }
        }
    printf("After sorting: \n");
    for(i=1;i<=n;i++)
    {
          printf("%d ",a[i]);
    }
    printf("\n");
//      getch();
}

Output:
nn@linuxmint ~ $ gcc c6.c
nn@linuxmint ~ $ ./a.out
Enter the number of elements: 5

Input the elements
5
4
3
2
1
After sorting:
1 2 3 4 5
nn@linuxmint ~ $

13 comments:

  1. Great Content. It will useful for knowledge seekers. Keep sharing your knowledge through this kind of article.
    Node JS Training in Chennai
    Perl Training in Chennai

    ReplyDelete
  2. Are you eager to embark on a transformative journey into the world of web development? Look no further! Our comprehensive web development courses in Kochi offer not only top-notch learning but also an exclusive opportunity for a free internship.

    ReplyDelete
  3. You explained the topic very well. The content has provided meaningful information thanks for sharing. intresting to gain knowledge then checkout our blog full stack course in pune

    ReplyDelete
  4. Elevate your skills with our Best Mern Stack Course In South Delhi , a carefully structured program that aims to impart a comprehensive understanding of full-stack web development through the MERN technology.

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...