简体   繁体   中英

function are not giving the output entered by the user in 2D Array format in C

The function isn't giving the correct number output entered by the user in value and the size of the array has been passed from main to the created function. The problem is that the output isn't showing up in 2 D Array format like rows and columns. Source code:

#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]);

You only have two %d specifiers here, but you send in three arguments after the format string. The only numbers that will be printed in this case are i+1 and n+1 . You need to have the format string

printf("The number are %d,%d: %d \n", i+1,n+1 ,td[i][n]);

In addition, consider marking the function todarr as void unless you intend to return a value from it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM