I'm trying to create a program whereby it will display a (5 digit integer).
An example would be if a user entered "23456", it will output "2 3 4 5 6".
I'm only allowed to capture the input(scanf) with integer(%d). I managed to do it without a for/while loop.
fivedigit = num / 10000;
fivedigitr = num % 10000;
fourdigit = fivedigitr / 1000;
fourdigitr = fivedigitr % 1000;
threedigit = fourdigitr / 100;
threedigitr = fourdigitr % 100;
twodigit = threedigitr / 10;
twodigitr = threedigitr % 10;
onedigit = twodigitr / 1;
onedigitr = twodigitr % 1
printf("%d %d %d %d %d\n", fivedigit,fourdigit,threedigit, twodigit, onedigit);
However, right now I'm needed to create a Version 2 using a loop. I'm unsure of how to cut the calculations short as to reduce the redundancy. The only thing that I managed to figure out is to reduce the "10000" by dividing by 10.
for(i=0; i<5; i++){
fivedigit = num / division2;
fivedigitr = num % division2;
division2 = division2/10;
}
Any help would be appreciated. I just need to know the basic ways on how to reduce the redundancy and I can move on from there and figure out.
Thanks.