C Program | Bubble sort User Define :

Write a C Program to Sort an array using Bubble sort , User Define Array :


Code:

#include<stdio.h>

void main()

{

    int a[20];

    int n,i,j,k;

    printf("Enter the size of array [20]:\n");

    scanf("%d",&n);

    printf("Enter the elements:\n");

    for(i=0;i<n;i++)

        scanf("%d",&a[i]);

    for(i=0;i<n;i++)

        for(j=0;j<n-1;j++)

        {

            if(a[j]>a[j+1])

            {

                k=a[j];

                a[j]=a[j+1];

                a[j+1]=k;

            }

        }

    for(i=0;i<n;i++)

        printf("%d\t",a[i]);

}

Output:

----------------------------------------------------------------------------

Bubble sort : Using Pointer

Comments

Popular posts from this blog

TOP 10 PROGRAMMING LANGAUAGES COMMING 2021 | ARTICLE

Write a C-program to swap two number:

Print Fibonacci Series using Recursion | C program :