/*Write a C program that reads N integer numbers and arrange them in ascending order using Bubble sort*/

 /*Write a C program that reads N integer numbers and arrange them in ascending order using Bubble sort*/

#include<stdio.h>

int main()

{

    int arr[50],i,j,n,temp;

    printf("Enter How many integers you want to arrange ?");

    scanf("%d",&n);

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

    {

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

    }

    printf("\n Elements of the array are :\n\n");

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

    {

        printf(" %d",arr[i]);

    }

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

    {

        for(j=i+1;j<n;j++)

        {

            if(arr[i]>arr[j])

            {

                temp=arr[i];

                arr[i]=arr[j];

                arr[j]=temp;

            }//end of if

        }//end of inner loop j

    }//end of outer loop i

    printf("\n Elements of the array are :\n\n");

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

    {

        printf(" %d",arr[i]);

    }

}//end of main


Comments