C++编程:将一个数组中的值按逆序重新存放,例如,原来顺序为:8,6,5,4,1。要求改为:1,4,5,6,8。
时间:2026-04-21 09:44:00
浏览:821次

这样写扩展性会更好,数组中的个数可以是任意的,只需修改arrSize 即可#include using namespace std;int main(){ unsigned int i = 0, j = 0, t = 0; const unsigned int arrSize = 5; int array[arrSize]; cout<<"enter the origil array:"<> array[i]; } for (i = 0, j = 0; j < arrSize /2; ++i, ++j) { t = array[i]; array[i] = array[arrSize - 1 - j]; array[arrSize - 1 - j] = t; } cout<<"the opposite array:"<
标签:C++,逆序,编程