編寫一個程序,讓用戶在數組中輸入10個數字。程序應該顯示數組中存儲的最大數字和最小數字。創建數組
我對之前考試的這個問題感到非常困惑,並且會在最後的考試中。任何幫助,將不勝感激!這就是我在測試中得到的結果,得到了3/15分,代碼幾乎完全錯誤,但是如果有必要,我可以發佈我的東西,謝謝!爲了創建數組,我至少可以開始這樣,所以這樣?
#include <iostream>
using namespace std;
int main()
{
int array(10); // the array with 10 numbers, which the user will enter
cout << "Please enter 10 numbers which will be stored in this array" << endl;
cin >> array;
int smallest=0; //accounting for int data type and the actual smallest number
int largest=0; //accounting for int data type and the actual largest number
//-both of these starting at 0 to show accurate results-
,然後在我的測試中,我開始使用for循環,並從那裏出來了凌亂的,所以我在這裏,我覺得最大的問題是如何真正比較/發現的最小和最大數,在最好的可能的方式。我也只是在大學計算機科學1,所以我們保持它很簡單,或者我喜歡。我們也知道二進制搜索和其他一種搜索方法,如果其中任何一種都是使用這種方法編寫代碼的好方法。謝謝!
非常感謝! @selbie – kdrumz