0% found this document useful (0 votes)
8 views1 page

Jadslaibilab 7 Task 2

Uploaded by

Jad.alslaiby04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Jadslaibilab 7 Task 2

Uploaded by

Jad.alslaiby04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <stdio.

h>

int sortArray(int arr[], int size) {


int i, j, temp;
for (i = 0; i < size - 1; i++) {
for (j = 0; j < size - 1 - i; j++) {
if (arr[j] > arr[j + 1]) {
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
return 0;
}

int printArray(int arr[], int size) {


for (int i = 0; i < size; i++) {
printf("%d ", arr[i]);
}
printf("\n");
return 0;
}

int main() {
int A;

printf("Enter the size of the array: ");


scanf("%d", &A);

int arr[A];

printf("Enter %d integers: ", A);


for (int i = 0; i < A; i++) {
scanf("%d", &arr[i]);
}

if (sortArray(arr, A) == 0) {
printf("Sorted array: ");
printArray(arr, A);
} else {
printf("Error in sorting the array.\n");
}

return 0;
}

You might also like