5th sem ADA programm to implement sorting algorithms

  • Bubble sort in c
#include<stdio.h>
void bubble(int n,int arr[]);
void main()
{
    int n;
    printf("enter the size of array:");
    scanf("%d",&n);
    int arr[n];
    int i,j,k;
    printf("enter the array elemets:\n");
    for(i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    bubble(n,arr);
     printf("\nyour sorted array is :\n");
    for(i=0;i<n;i++)
    {
        printf("%d\n",arr[i]);
    }

}
void bubble(int n, int arr[n])
{
    int i,j,swap;
    for(i=0;i<n;i++)
    {
        for(j=0;j<n-i-1;j++)
        {
            if(arr[j]>arr[j+1])
            {
                swap=arr[j];
                arr[j]=arr[j+1];
                arr[j+1]=swap;
            }
        }
    }

}

Comments

Popular posts from this blog

5th sem OOPJ Write an interactive program to print a diamond shape. For example, if user enters the number 3, the diamond will be as follows:

SQL Lab 3

SQL Lab 6