Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Name: Deepak Maurya

Batch: A Roll no: 22

Selection sort
Program:

#include<stdio.h>

#include<conio.h>

void selection(int a[],int n)

int i,j,min,temp;

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

min=i;

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

if(a[j]<a[min])

min=j;

temp=a[min];

a[min]=a[i];

a[i]=temp;

void main()

int a[20];

int i;

printf("enter the number of element");

scanf("%d",&n);

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

{
Name: Deepak Maurya
Batch: A Roll no: 22

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

selection(a,n);

printf("sorted element\n");

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

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

getch();

Output:

Insertion sort
Name: Deepak Maurya
Batch: A Roll no: 22

Program:
#include<stdio.h>

#include<conio.h>

void inssort(int a[], int n)

int i,j,temp;

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

temp=a[i];

j=i-1;

while(j>=0&&a[j]>temp)

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

j--;

a[j+1]=temp;

void main()

int a[100];

int i,n;

clrscr();

printf("enter the number of element");

scanf("%d",&n);

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

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

inssort(a,n);

printf("sorted element\n");

for(i=0;i<n;i++)
Name: Deepak Maurya
Batch: A Roll no: 22

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

getch();

Output:

Bubble sort

Program:
Name: Deepak Maurya
Batch: A Roll no: 22

#include<stdio.h>

#include<conio.h>

void sortb(int a[],int n)

int i,j,temp;

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

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

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

temp=a[j];

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

a[j+1]=temp;

void main()

int a[100];

int i,n;

clrscr();

printf("enter the number of element");

scanf("%d",&n);

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

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

sortb(a,n);

printf("sorted element\n");
Name: Deepak Maurya
Batch: A Roll no: 22

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

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

getch();

Output:

You might also like