c - Printing numbers in zigzag order in 2 D array -


#include <stdio.h>  int main(){      int i,j;      int flag = 0;     int x [3][3] = {{1,2,3},{4,5,6},{7,8,9}};     (i = 0;i<3;i++){         if (flag ==1){              (j=2;j<0;j--){                 printf(" %d",x[i][j]);              }             flag =0;         }         else  {             (j=0;j<3;j++)             {                 printf(" %d ",x[i][j]);             }             flag =1;         }     }     return 0; } 

i'm trying print numbers in array in zigzag form expected output should 123654789 got 123789 reason dont enter loop in flag condition want know reason.. in advance

instead of

        (j=2;j<0;j--){ 

use

        (j=2;j>-1;j--){ 

and (only nice formatting) instead of

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

(near end, space after %d) use

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

(without space).


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -