2 qq 35843384 qq_35843384 于 2017.01.10 12:35 提问

c++如何将二维数组元素逆序储存

比如a[3][3]={{1,2,3},{4,5,6},{7,8,9}}换成
a[3][3]={{9,8,7},{6,5,4},{3,2,1}}

1个回答

JE_GE
JE_GE   2017.01.10 13:00
 #include <stdio.h>

void chage(int array[], int n)
{
    int tem;
    for (int i = 0; i < n/2; i++)
    {
        tem = array[i];
        array[i] = array[n-1-i];
        array[n-1-i] = tem;
    }
}

int main()
{
    int a[] = {0,1,2,3,4,5,6,7,8,9};
    chage(a, 10);
    for (int i = 0; i < 10; i++)
        printf("%d ", a[i]);
    printf("\n");
}
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!