📄 program_9_1.cpp
字号:
// Program 9.1: Display inputs in reverse order
#include <iostream>
using namespace std;
void GetList(int A[], int MaxN, int &n);
void Swap(int &Value1, int &Value2);
void PutList(const int A[], int n);
// main(): manage extraction, reversal, and display of list
int main() {
const int MaxListSize = 100;
int Number[MaxListSize];
int n;
cout << "Please input a list, end with \"ctrl+z\"" << endl;
GetList(Number, MaxListSize, n);
for (int i = 0; i< n/2; ++i) {
// swap element from front of list with
// corresponding element from the end of the list
Swap(Number[i], Number[n-1-i]);
}
PutList(Number, n);
return 0;
}
// GetList(): extract up to MaxN value from input into A
void GetList(int A[], int MaxN, int &n) {
for ( n =0; (n<MaxN) && (cin>>A[n]); ++n ) {
continue;
}
}
// Swap(): interchange value of parameters
void Swap(int &Value1, int &Value2) {
int tmp = Value1;
Value1 = Value2;
Value2 = tmp;
}
// PutList(): display n elements of A
void PutList(const int A[], int n) {
for (int i=0; i<n; ++i) {
cout << A[i] << endl;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -