簡體   English   中英

從C ++中的整數數組獲取輸入

[英]Taking input from an array of integers in C++

所有,我對C ++還是很陌生。 我的老師給了我們創建一個函數的任務,該函數可以執行以下操作:

//addbig( ) -- This function is sent an array of integers and the length 
//of the array.  
//It returns the sum of all integers in the array that are larger than 1000.

也許是因為,英語是我的第二語言,但我真的不明白他在這里問的是什么。

另外,當從用戶那里獲取輸入時,我使用cin >>時數組將由字符組成。 但是我試圖用它來接收整數數組的輸入,但並沒有讓我這樣做。 我必須先進行轉換嗎?

如果你們中的任何一個能有所啟發,那就太好了。

我認為您應該從功能參數開始。 它說addBig有兩個參數,分別是整數數組和數組的長度。

int addBig(int arr[], int sze)
{
     int sum = 0;
     // do summation.
     return sum;
}

至於整數的輸入

const size_t N = 10;
int a[N];

std::cout << "Enter " << N << " integer values: ";
for ( size_t i = 0; i < N; i++ ) std::cin >> a[i];

至於功能,那么你應該聲明為

int addbig( int a[], size_t n );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM