Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - C language programming question: Input a long integer and output it gradually starting from the high bit. For example, input 123456 and output 1, 2, 3, 4, 5.
C language programming question: Input a long integer and output it gradually starting from the high bit. For example, input 123456 and output 1, 2, 3, 4, 5.

#include?

#include?

#include?

< p>int?main(int?argc,?char?**?argv)?{

void?print_num(long?number);

print_num(123456);

p>

return?1;

}

void?print_num(long?number)?{

int?digits?=?floor(log10 (abs(number)))?+?1;?//?Find the number of digits in an integer

int?array[digits];

int?i?=?digits? -?1;

while?(number)?{ //?Extract each digit (starting with the ones digit) and store it in the array

array[i]?=?number? %?10;

number?/=?10;

i--;

}

for?(i?= ?0;?i?

if?(i?==?digits?-?1)

< p> printf("%d",?array[i]);//?The last number does not need to be separated by commas

else?

printf("%d,?" ,?array[i]);

}

}

The output result is: