編程,定義10個元素的整型數組,從鍵盤輸入數存入該數組,然后逆序打印該數組。(數組作業)


#include<iostream>

using namespace std;

int main() {

int arr[10] = {};

cout << "請輸入十個數組元素" << endl;

for (int i = 0; i < 10; i++) {

cout << "第" << i + 1 << "個元素:" << "";

cin >> arr[i];

cout << endl;

}

for (int i = 0; i < 10; i++) {

for (int j = i + 1; j < 10; j++) {

if (arr[i] < arr[j]) {

int temp = arr[i];

arr[i] = arr[j];

arr[j] = temp;

}

}

}

for (int i = 0; i < 10; i++) {

cout << arr[i] << endl;

}

return 0;

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM