这道c++编程题怎么做?
2个回答
展开全部
这题应该有错,第4步的old应该是odd,然后前面描述MIX()函数带4个参数,后面要求A、B、C都是参数,加上A、B的数组大小,应该是5个参数才对,如果是4个参数的话,C应该是以返回值形式带回。下面代码把~换成空格:
/////////////////////////////////////////////////////
int *MIX(int A[], unsigned int M, int B[], unsigned int N) {
~~~~int *C = new int[M+ N];
~~~~unsigned int i, j = 0, k = M+ N - 1;
~~~~for (i = 0; i<M ;i++) {
~~~~~~~~if (A[i] % 2 == 0) {
~~~~~~~~~~~~C[j++] = A[i];
~~~~~~~~} else {
~~~~~~~~~~~~C[k--] = A[i];
~~~~~~~~}
~~~~}
~~~~for (i = 0; i<N ;i++) {
~~~~~~~~if (B[i] % 2 == 0) {
~~~~~~~~~~~~C[j++] = B[i];
~~~~~~~~} else {
~~~~~~~~~~~~C[k--] = B[i];
~~~~~~~~}
~~~~}
~~~~return C;
}
/////////////////////////////////////////////////////
int *MIX(int A[], unsigned int M, int B[], unsigned int N) {
~~~~int *C = new int[M+ N];
~~~~unsigned int i, j = 0, k = M+ N - 1;
~~~~for (i = 0; i<M ;i++) {
~~~~~~~~if (A[i] % 2 == 0) {
~~~~~~~~~~~~C[j++] = A[i];
~~~~~~~~} else {
~~~~~~~~~~~~C[k--] = A[i];
~~~~~~~~}
~~~~}
~~~~for (i = 0; i<N ;i++) {
~~~~~~~~if (B[i] % 2 == 0) {
~~~~~~~~~~~~C[j++] = B[i];
~~~~~~~~} else {
~~~~~~~~~~~~C[k--] = B[i];
~~~~~~~~}
~~~~}
~~~~return C;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |