Question: I need help completing this one in C please. Just edit the part where it says enter your code here. So the part that I
I need help completing this one in C please. Just edit the part where it says "enter your code here". So the part that I need help with is writing a recursion code that asks the user two arrays, A[] and B[] for up to 10 integers for its input. Array A[] should be sorted in ascending and B[] in descending order. Please print out all the numbers in ascending order.
So for example, if A[]= {1 3 5 7 9} and B[]= {8 6 4 2}, the output should be 1 2 3 4 5 6 7 8 9
1. the user is going to enter numbers one by one, separated by a single
space. When the first array is done, an ENTER (' ') will be used
as input and the second array will start.
2. each array input will not have more than 10 integers
*/
#include
void sort(int [], int, int, int [], int, int);
// this is the recursive function that you are supposed to implement
int main()
{ int A[10], B[10], cnt_a, cnt_b;
int i, j;
char ch;
printf("Enter the first array:");
i = 0;
do
{ scanf("%d%c", &A[i], &ch);
// read in an integer that next character ch
// use the value of ch to check whether there is more numbers ( )
// or the first array has reached the end ( )
i++;
} while (ch==' ' && i<10);
cnt_a = i;
printf("Enter the second array:");
i = 0;
do
{ scanf("%d%c", &B[i], &ch);
i++;
} while (ch==' ' && i<10);
cnt_b = i;
sort(A, 0, cnt_a-1, B, 0, cnt_b-1);
printf(" ");
return 0;
}
void sort (int A[], int a, int b, int B[], int c, int d)
{
// write your code here!
// the following code tests input has been read in correctly
int i;
printf("1st array:");
for (i=0; i<=b; i++)
printf(" %d", A[i]);
printf(" 2nd array:");
for (i=0; i<=d; i++)
printf(" %d", B[i]);
printf(" ");
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
