Write a c program for bubble sort ?
#include<stdio.h>
int main()
{
int array[100], n, i, j, temp = 0;
printf("Enter how many numbers you want:\n");
scanf("%d", &n);
printf("Enter the %d elements:\n", n);
for (i = 0; i < n; i++)
{
scanf("%d", &array[i]);
}
printf("\nThe given array is:\n");
for (i = 0; i < n; i++)
{
printf("\n%d", array[i]);
}
for (i = 0; i < n; i++)
{
for (j = i + 1; j < n; j++)
{
if (array[i] > array[j])
{
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
printf("\n\n\n\t\tThe sorted array using Buble sort is:\n");
for (i = 0; i < n; i++)
{
printf("\n\t\t%d", array[i]);
}
return 0;
}
No comments:
Post a Comment