c语言数组数据的输入,在C语言中,数组中的值如何输入到函数中?
我希望這有幫助:
#include
/* don't need to specify size of array1 here */
/* rather pass the no. of elements of array1 through n*/
int FillArray(int array1[], int n) {
/* observe, you've 10 elements in array1 */
/* that's why array2[10] */
/* size of array2 should be >= n */
int array2[10], i;
/* I replaced 9 with 10 as array1 */
/* has n elements...ranges 0 to n-1 */
for(i = 0; i < n; ++i) {
if (array1[i] > 0)
array2[i] = array1[i] * 2;
else
array2[i] = array1[i] * 10;
/* I didn't get this below line. */
/* Should it be outside the loop? or what you've tried to do here. */
/* If you want to print the content of array2,*/
/* then see your book how to print an array */
/* for an array of size n,*/
/*it's index range is 0 to n-1.....so 10 is not valid */
// printf("
%d", array2[10]); // this line
}
/* To print array2, in case if you want to know about it */
for(i=0; i
printf("%d
", array2[i]);
}
return 0;
}
int main() {
/* you don't have to specify size here */
/* but again, if you would like to specify */
/* it would be >= 10 as you've at least 10 elements in array1 */
int array1[] = { 40, 13, -5, 22, 10, 80, -2, 50, 9, -7 };
/* it's good habit to pass the no. of elements of an array */
FillArray(array1, 10);
return 0;
}
總結
以上是生活随笔為你收集整理的c语言数组数据的输入,在C语言中,数组中的值如何输入到函数中?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: stm32f746 linux,在Lin
- 下一篇: c语言 中insert变量值,c – 在