arrays - C, printf loop and line change -
i new @ c programming.
i have 1-d array (size of array given user, containing seat numbers)
i want print result in screen divide results in multiple rows. each row should have 4 elements of array, , last 1 more elements.
probably use loop combined printf
can't think of way combine them.
so have tried , works not elegant code, have repeat 15 times.
(i = 0; < 4; i++) { if (seatnr[i] = 1) printf("1"); else printf("0"); } printf("\n"); (i = 4; < 8; i++) { if (seatnr[i] = 1) printf("1"); else printf("0"); } printf("\n"); (i = 8; < 12; i++) { if (seatnr[i] = 1) printf("1"); else printf("0"); }
for (j = 0; j < n; j+=4) { (i=j; < j+4; i++) { if (seatnr[i]==1) printf("1"); else printf("0"); } printf("\n"); }
Comments
Post a Comment