Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main() {
- int size, i, j, temp;
- printf("Enter the size of the array: ");
- scanf("%d", &size);
- int arr[size];
- printf("Enter the elements of the array:\n");
- for (i = 0; i < size; i++) {
- scanf("%d", &arr[i]);
- }
- printf("Original array: ");
- for (i = 0; i < size; i++) {
- printf("%d ", arr[i]);
- }
- printf("\n");
- // Bubble Sort algorithm
- for (i = 0; i < size - 1; i++) {
- for (j = 0; j < size - 1 - i; j++) {
- if (arr[j] > arr[j + 1]) {
- // Swap elements
- temp = arr[j];
- arr[j] = arr[j + 1];
- arr[j + 1] = temp;
- }
- }
- }
- printf("Sorted array: ");
- for (i = 0; i < size; i++) {
- printf("%d ", arr[i]);
- }
- printf("\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment