+ 1

Program using nested for loop?

1 12 123 1234 Code to print it on the right side Like 1 2 1 321 4321 I tried this #include <stdio.h> int main() { int ct,gk; for(ct=1;ct<=4;ct++) { for(gk=1;gk<=ct;++gk) { printf("%d",gk); } printf("\n"); } return 0; }

15th Oct 2019, 7:36 PM
Alfred Monir
Alfred Monir - avatar
6 Answers
+ 6
For right aligned printing #include <stdio.h> int main() { int ct, gk, p; for (ct = 1, p = 3; ct <= 4; ct++) { // print padding spaces if(p) printf("%*c", p--, ' '); // loop backwards for (gk = ct; gk >= 1; --gk) printf("%d", gk); printf("\n"); } return 0; }
15th Oct 2019, 8:11 PM
Ipang
+ 6
what do you need help with? 😅 (and a side note, it hurts to see unindented code đŸ˜©, it makes it alot harder to understand the code and just doesn't look pretty and clean 😅)
15th Oct 2019, 8:06 PM
Anton Böhler
Anton Böhler - avatar
+ 4
You're welcome Alfred, Next time around, please save the code in your profile, and share the link instead, easier for review, and yes, need a little work with code indentation 😁
15th Oct 2019, 8:24 PM
Ipang
+ 3
Ipang Thank you I understood
15th Oct 2019, 8:17 PM
Alfred Monir
Alfred Monir - avatar
+ 3
Anton Böhler ok I will try to take care of that from next time
15th Oct 2019, 8:20 PM
Alfred Monir
Alfred Monir - avatar
+ 1
Ipang hmm ok😊
15th Oct 2019, 8:34 PM
Alfred Monir
Alfred Monir - avatar