Question-Implement the Selection Sort, Bubble Sort and Insertion sort
algorithmsona set of 25numbers. (Refer Figure 8.11 for the
logic of the algorithms)
− Selection sort
Solution-
Very famous and important example of array. I am Writing a general program to sort out the any number of numbers.so, let's look up the solution.
#include<stdio.h>
#define m 5
int main()
{
int i,j,k,t;
int arr[m];
printf("Enter 5 numbers\n");
for(i=0;i<m;i++)
scanf("%d",&arr[i]);
for(j=0;j<=m-1;j++)
{
for(k=j+1;k<=m-1;k++)
{
if(arr[j]>arr[k])
{
t=arr[k];
arr[k]=arr[j];
arr[j]=t;
}
}
}
for(i=0;i<=m-1;i+=1)
printf("%d ",arr[i]);
return 0;
}
algorithmsona set of 25numbers. (Refer Figure 8.11 for the
logic of the algorithms)
− Selection sort
Solution-
Very famous and important example of array. I am Writing a general program to sort out the any number of numbers.so, let's look up the solution.
#include<stdio.h>
#define m 5
int main()
{
int i,j,k,t;
int arr[m];
printf("Enter 5 numbers\n");
for(i=0;i<m;i++)
scanf("%d",&arr[i]);
for(j=0;j<=m-1;j++)
{
for(k=j+1;k<=m-1;k++)
{
if(arr[j]>arr[k])
{
t=arr[k];
arr[k]=arr[j];
arr[j]=t;
}
}
}
for(i=0;i<=m-1;i+=1)
printf("%d ",arr[i]);
return 0;
}
/* we can easily use this program to sort out any number of numbers, just by changing the macro value i.e. m 25 or m 50. */
did not run ,has too many errors
ReplyDeletethanks friend
ReplyDeleteplease send me A 6 x 6 matrix is entered through the keyboard and stored in a 2-dimensional array mat[7][7]. Write a program to obtain the Determinant values of this matrix.
ReplyDelete