Friday, 23 August 2013

Chapter 8 Solutions Problem [C][c]-Part 2

Question-Implement the Selection Sort, Bubble Sort and Insertion sort
algorithmsona set of 25numbers. (Refer Figure 8.11 for the
logic of the algorithms) 
−  Bubble Sort
Solution- it's again an interesting program. let's look up the solution. Also watch out for the difference between different sorting techniques.

#include <stdio.h>
#include <stdlib.h>

int main()
{
int arr[25];
int i,j,k,*m;
printf("Enter 25 numbers\n");
for(i=0;i<=24;i++)
scanf("%d",&arr[i]);
for(j=24;j>0;j--)
{
for(i=0;i<24;i++)
{
if(arr[i]>arr[i+1])
{
k=arr[i];
arr[i]=arr[i+1];
arr[i+1]=k;
}
}
}
m=&arr[0];
printf("Numbers in Ascending order\n");
for(i=0;i<=24;i++)
{
printf("%d\n",*m);
m++;
}
getch();
}

1 comment:

  1. hwen you have not used k,then why declared in it....it is wrong while executing

    ReplyDelete