Write a program to accept 5 numbers and sort them using bubble sort. (Single Dimension Arrays)

/* Write a program to accept 5 numbers and sort them using bubble sort.

(Single Dimension Arrays)*/

#include <stdio.h>

void main()

{

    int arr[5],i,j,t;

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

    {

        printf("Enter the value of Arr[%d] : ",i+1);

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

    }

    printf("The elements before sorting :=\n");

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

    {

        printf("Arr[%d] : %d\n",i+1,arr[i]);

    }

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

    {

        for(j=4;j>i;j--)

        {

            if(arr[j-1]>arr[j])

            {

                t=arr[j-1];

                arr[j-1]=arr[j];

                arr[j]=t;

            }

        }

    }

    printf("The elements after sorting :=\n");

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

    {

        printf("Arr[%d] : %d\n",i+1,arr[i]);

    }

    getch();

}

Comments

Popular posts from this blog

Write a program to accept numerator and denominator and find the remainder without using modulus (%) operator using do..while loop.