Hello everyone I'm a beginner in coding and I try to figure out how to output all the digits. Example in the number 158 the number 1,5,8,15,58,158. Sorry for the bad English.
I have tried something but it doesnt work for all numbers plus i believe there must be a better way to code it without all the while loops.
#include <stdio.h>
int main(){
long num = 5025;
int num1=num ,num2= num, num3=num;
while(num1 !=0)
{
int digit = num1 % 10;
num1 = num1/10;
printf("%d\n", digit);
}
while(num2 >10)
{
int digit = num2 % 100;
num2 = num2 / 10;
printf("%.2d\n", digit);
}
while(num3 >100)
{
int digit = num3 % 1000;
num3 = num3 / 10;
printf("%.3d\n", digit);
}
return 0;
}