Write A Program Input 10 integer elements in an array and sort them in Ascending order using the bubble short Technique
Answers
Answered by
0
Explanation:
// Bubble short
#include <stdio.h>
int main() {
int array[50], n, i, j, swap;
printf("\n Enter number of elements\n");
scanf("%d", &n);
printf("\n Enter %d integers\n", n);
for (i = 0; i < n; i++)
scanf("%d", &array[i]);
for (i = 0; i < (n - 1); i++) {
for (j = 0; j < n - i - 1; j++) {
if (array[j] > array[j + 1]) /* For decreasing order use < */
{
swap = array[j];
array[j] = array[j + 1];
array[j + 1] = swap;
}
}
}
printf("Sorted list in ascending order:\n");
for (i = 0; i < n; i++)
{
printf("%d\n", array[i]);
}
return 0;
}
Similar questions
Math,
2 months ago
Physics,
2 months ago
Social Sciences,
2 months ago
English,
5 months ago
Political Science,
5 months ago
Computer Science,
11 months ago