+ 1
How to print stack in C ?
my output : | | | 7 | |____| | | | 8 | |____| | | | 9 | |____| | | | 10 | |____| Output I am expecting : | | | 7 | |____| | | | 8 | |____| | | | 9 | |____| | | | 10 | |____| It should work for any digit number like if their is one element 100000 then all the elements should be align correctly... my attempt : https://code.sololearn.com/c0W7aMNo45WC/?ref=app
2 Respuestas
+ 4
This will work up to 4 digits:
printf("| |\n| %4d |\n|______|\n", i);
If you want more flexibility you will need to determine the longest element in your stack, and adjust the number of space and underscore characters accordingly too.
You can find some ideas how to do that, here:
https://stackoverflow.com/questions/4133318/variable-sized-padding-in-printf
+ 4
https://code.sololearn.com/cCa2mAacqvtH/?ref=app