You get the tens, hundreds and thousands in the same way that you got the units (remembering to reduce the number by factors of 10 before you find each of them).
I'm afraid that looking at your post
int tens = n1 & 99;
scanf("%d", &n1); |
I really don't understand your line of thinking. So ... not like that!
Take a numerical example: let's say n1 is input as 3584.
If you set units to n1 % 10 you will get units=4.
Then doing
n1 /= 10;
you will reduce n1 to 358.
Now set tens to n1 % 10, to get tens=8.
Doing
n1 /= 10;
again you will reduce n1 to 35.
Now set hundreds to n1 % 10, to get hundreds=5.
Doing
n1 /= 10;
again you will reduce n1 to 3.
You are left with the number of thousands.
I don't really see where any
if
statements come into this, unless you choose not to print particular output or you want to stop as soon as a number becomes 0.