![](/img/trans.png)
[英]In C, iterative function is not giving the right output which is supposed to be a number not in sum(from data entered by user) or in data array?
[英]function are not giving the output entered by the user in 2D Array format in C
function 沒有給出用戶輸入的正確數字 output 值,並且數組的大小已從主傳遞到創建的 function。 問題是 output 沒有像行和列那樣以二維數組格式顯示。 源代碼:
#include <stdio.h>
int todarr(int td[4][2]){
for(int i=0;i<4;i++){
for(int n=0;n<2;n++){
printf("The number are %d,%d \n", i+1,n+1 ,td[i][n]);
}
}
}
int main()
{
int td[4][2];
for(int i=0;i<4;i++){
for(int n=0;n<2;n++){
printf("Enter the number \n");
scanf("%d", &td[i][n]);
}
}
todarr(td);
return 0;
}
printf("The number are %d,%d \n", i+1,n+1 ,td[i][n]);
您在這里只有兩個%d
說明符,但您在格式字符串之后發送了三個 arguments。 在這種情況下,將打印的唯一數字是i+1
和n+1
。 你需要有格式字符串
printf("The number are %d,%d: %d \n", i+1,n+1 ,td[i][n]);
此外,考慮將 function todarr
標記為 void,除非您打算從中返回值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.