Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void print_array(int a[], int n) // print values of an array
- {
- for(int i = 0; i < n; i++)
- {
- printf("%d ", a[i]);
- }
- printf("\n");
- }
- void sort_array(int a[], int n) // sort array
- {
- for(int i = 0; i < n; i++)
- {
- for(int j = 0; j < n; j++)
- {
- if(a[j] > a[i])
- {
- int tmp;
- tmp = a[i];
- a[i] = a[j];
- a[j] = tmp;
- }
- }
- }
- }
- int main()
- {
- int a[10] = {3, 4, 5, 2, 1, 8, 9, 6, 7, 12};
- printf("array : ");
- print_array(a, 10);
- sort_array(a, 10);
- printf("sorted array : ");
- print_array(a, 10);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement