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

Popular posts from this blog

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

laravel - Undefined property: Illuminate\Pagination\LengthAwarePaginator::$id (View: F:\project\resources\views\admin\carousels\index.blade.php) -