Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

you need to write a C function named mix. The prototype is: int mix(char*, char*

ID: 3595694 • Letter: Y

Question

you need to write a C function named mix. The prototype is:

int mix(char*, char*, char*);

Let's suppose your function is written with the following argument list:

int mix(char *A, char *B, char *out)

The function should set out to be a mixture of A and B. Specifically,
out consists of the following (in this order):
A[0]
B[0]
A[1]
B[1]
A[2]
B[2]
...
followed finally by a null terminator ('')

You may assume A and B have the same length. The output string (out) will thus be exactly twice the length of A (or B).

If your function is in a file named mix.c, and your test code is in
a file named main.c, then you can compile as follows:

gcc -o main main.c mix.c

Explanation / Answer

#include <iostream>
#include <string>
using namespace std;
int mix(char *A, char *B, char *out) {
int j =0;
for(int i=0;A[i] !='';i++,j++ ) {
out[j++] = A[i];
out[j] = B[i];
}
return j;
}
int main() {
char A[50] = "abcde";
char B[50] = "zyxvu";
char C[50];
mix(A, B, C);
cout<<"Mix: "<<C<<endl;
return 0;
}

Output: