hello every body here i got some problem with assign value to arrays, so i want to print multiplication table of the arrays:

#include <stdio.h>
 int main(){
   int x=5;
   int y=5;
   int i,j;
   int tab[x][y];
   for( i=0; i<x; i=i+1){
     tab[i][j]=i;
     for(j=0; j<y; j=j+1){
       tab[i][j]=i;
     printf("%d", tab[x][y]);
     }
     printf("\n");
   }
   return 0;
 }

i'm getting like
00000
00000
00000
00000
00000

Member Avatar for misi

What happens if:

printf("%d", tab[i][j]);

oh man merci man. i'm felling stupid now

Member Avatar for misi

In the future declare your array with constants.
int tab[5][5];
My compiler does not accept: int tab[x][y];

Do you really need line 8 ?

not really i deleted it ;) hello again i would like to to move a number in arrays like if number 1 is in array[2][5] and user enter 4 the value 1 goes in arrays[1][5] but not working with my code i can't undestund why i'm getting all 0

#include <stdio.h>
int main(){
  int x=11;
  int y=11;
  int i,j;
  int map[x][y];
  map[5][5]=1;
  for (i=0; i<x; i++){
    for (j=0; j<y; j++){
      map[i][j]=0;
    }
  }
  int mouv;
  printf("deplace vers?");
  scanf("%d", &mouv);
  printf("%d\n",mouv);
  if(mouv==4){
  map[i-1][j]=1;
}
if(mouv==6){
map[i+1][j]=1;
}
else if(mouv==2){
map[i][j-1]=1;
}
else if(mouv==8){
map[i][j+1]=1;
}
  for (i=0; i<x; i++){
    for (j=0; j<y; j++){
      printf("%d", map[i][j]);
    }
    printf("\n");
  }
return 0;
}

Read your code. Notice that by line 12, the array is indeed all zeros. And i, j are pointing at the last element of the array. And line 7's effect is wiped out. As in, map[5,5] is zero by line 12.

So read your code at 13 and i, j are 11, and 11 and line 21 could cause a code failure.

i and j are 11 until about line 29.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.