what printf should i use to get this effect

I want to print a n*n array with words filled(in this case, is 4by4, but could be other size as well). I'm wondering how to align the words and numbers like the sample below.

1
2
3
4
5
                     0                 1                 2                 3
 0       Homer Simpson            Cypher            Cypher       Enchantress
 1              Mirage            Cerise        Spider-Man              Toad
 2       Homer Simpson            Thanos            Mirage            Cerise
 3         Enchantress            Thanos              Toad        Spider-Man
Last edited on
Use tabs to align the headins 0,1,2 and 3.
use printf("%15s\t%10s\t%10s\t%15s\n"); for the rest
Last edited on
I got the idea but the column and row's size vary and could be 4, 6, 8, or 10. Should I write if statement to do this? I think there are easier ways.
Topic archived. No new replies allowed.