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
Post a Comment