/* *************************************************
22. TO SEARCH ELEMENTS USING BUBBLE SORTING .
*************************************************** */
#include<*stdio.h>
#include<*conio.h>
#define MAXSIZE 50
void bubblesort(int arr[],int n);
int arr[MAXSIZE],n;
void main()
{
int i;
clrscr();
printf("\n how many elements are there : ");
scanf("%d",&n);
printf("\n\n enter the elements : ");
for(i=0;i
scanf("\t%d",&arr[i]);
printf("\n\n elements before sorting : ");
for(i=0;i
printf("\t%d",arr[i]);
bubblesort(arr,n);
printf("\n\n elements after sorting : ");
for(i=0;i
printf("\t%d",arr[i]);
getch();
}
void bubblesort(int arr[],int n)
{
int i,j,temp;
for(i=0;i
{
for(j=0;j
{
if(arr[i]
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
}
output
how many elements are there : 3
enter the elements : 3 2 1
elements before sorting : 3 2 1
elements after sorting : 1 2 3
22. TO SEARCH ELEMENTS USING BUBBLE SORTING .
*************************************************** */
#include<*stdio.h>
#include<*conio.h>
#define MAXSIZE 50
void bubblesort(int arr[],int n);
int arr[MAXSIZE],n;
void main()
{
int i;
clrscr();
printf("\n how many elements are there : ");
scanf("%d",&n);
printf("\n\n enter the elements : ");
for(i=0;i
scanf("\t%d",&arr[i]);
printf("\n\n elements before sorting : ");
for(i=0;i
printf("\t%d",arr[i]);
bubblesort(arr,n);
printf("\n\n elements after sorting : ");
for(i=0;i
printf("\t%d",arr[i]);
getch();
}
void bubblesort(int arr[],int n)
{
int i,j,temp;
for(i=0;i
{
for(j=0;j
{
if(arr[i]
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
}
output
how many elements are there : 3
enter the elements : 3 2 1
elements before sorting : 3 2 1
elements after sorting : 1 2 3
0 comments:
Post a Comment