Regarding the problem of finding the number of digits in an integer, output each digit in reverse order, and output each digit in order.

Regarding the problem of finding the number of digits in an integer, output each digit in reverse order, and output each digit in order.

I am a computer beginner. It is my first time to write a blog. I have chosen a basic but important question. There may be many omissions in the blog content. I hope readers will understand. You can like or criticize as you wish.
First, we start by finding the number of digits in an integer

Find the number of digits in an integer

The basic idea is as follows:
First, get an arbitrary integer n, and set a digit counter count. First initialize the digit counter count to 0. Then, the integer n is divided by 10. Each time the integer n is divided, the integer n is reduced by 1, so the digit counter is increased by 1 at the same time. This operation is repeated until the integer is 0. At this time, the value in the digit counter count This is the number of digits in the integer n. However, it is worth noting that if the integer n is 0, the integer is divided by 10, and the operation of adding 1 to the digit counter count is not performed because the integer is 0, so the value of count is 0, and 0 is a single digit, so this is unreasonable. Therefore, it is necessary to additionally define the description that when the integer n is 0, the number of digits is 1. The following is the implementation code in C language:

int Count(int n){
   
    
    
	int count;
	if(n == 0){
   
    
    
		return 1;
	}
	while(n != 

Guess you like

Origin blog.csdn.net/HuoYukai/article/details/102559451