Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void add_element(int *arr, int n, int currpos, int newel)
- {
- if(currpos == n) arr[currpos] = newel;
- else {
- if(newel >= arr[currpos])
- {
- int k = arr[currpos];
- arr[currpos] = newel;
- return add_element(arr, n, currpos + 1, k);
- }
- return add_element(arr, n, currpos + 1, newel);}
- }
- int main()
- {
- int *arr = (int *)malloc(sizeof(int) * 16);
- arr[0] = 9;
- arr[1] = 7;
- arr[2] = 6;
- arr[3] = 5;
- arr[4] = 2;
- arr[5] = 1;
- add_element(arr, 7, 0, 3);
- for(int i = 0; i < 7; i++)
- {
- printf("%d\n", arr[i]);
- }
- free(arr);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement