【发布时间】:2022-01-04 09:09:53
【问题描述】:
cout << "Enter number:" << endl;
// number has to be stored in array
cin >> input[number];
// function has to work with every element and element that is 2 positions further
gcd(input[0], input[0+2]);
【问题讨论】:
-
C 方式:将指向第一个元素的指针与数组中的元素数一起传递。 C++ 方式:使用
std::vector<int>并将const引用传递给向量。 -
或同时适用于
C和C++的STL 方式,传递一个指向第一个元素的指针和一个指向最后一个元素之后的指针:gcd(input, input + 2);。 -
gcd的签名是什么? -
gcd(查找除数的函数名称)
-
旁白:您的 cmets 与您的代码不匹配。
number被用作索引,它不是存储在input中任何位置的值