Can anybody pls explain this logic and working of program. Mainly why we are using semicolon after the first for loop. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can anybody pls explain this logic and working of program. Mainly why we are using semicolon after the first for loop.

https://code.sololearn.com/cQXxRWI9xGj6/?ref=app

19th Nov 2021, 3:04 PM
Akhil.OR
Akhil.OR - avatar
3 Answers
+ 4
For 1234 i become 1000 Then 1234%1000=234 Then 234%100=34 . . So it's printing 1234 234 34 4 Jayakrishna🇮🇳 I think you just reversed it.. just check your answer
19th Nov 2021, 4:54 PM
Arun Ruban SJ
Arun Ruban SJ - avatar
+ 1
Its printing pattern like ex: 1234 123 12 1 So there first loop find 10 power of number of digits.. for 1234 =>I=1000 So then 2nd loop prints 1234 and makes n=1234%100=>123 This is repeated till n>0; Semicolon at the end of loop means there is no body or statements in for the loop... Remove warning.. why long int main()? use int main(){..} instead of %ld (used for long int ) , use %d (used for int type) Hope it helps.. edit: Akhil.OR yes. it actually a bit reverse print, instead n/I, its working n%i so it's printing reminder instead of quotient . so output is 1234 234 34 4 remaining all works same.
19th Nov 2021, 3:56 PM
Jayakrishna 🇮🇳
+ 1
Arun Ruban SJ yes. I focused on question instead of output. Iam not noticed that. it actually a bit reverse print, instead n/I, its working n%i so it's printing reminder instead of quotient . so output is 1234 234 34 4 Remaining almost same works..,👍👍
19th Nov 2021, 8:40 PM
Jayakrishna 🇮🇳