Flashback output a number

Flashback output a number

#include<stdio.h>
int getlen(int n)//统计数字的长度
{
    
    
	int i=0;
	while(n)
	{
    
    
		n/=10;
		i++;
	}
	return i;
}
int getindex(int i)//求数字的指数
{
    
    
	int j=1;
	for(;i>0;i--)
	{
    
    
		j*=10;
	}
	return j;
}
int main()
{
    
    
	int n,i=0,len,lastnum=0;
	scanf("%d",&n);
	len=getlen(n);
	while(n)
	{
    
    
		lastnum+=n%10*getindex(len-i-1);
		i++;
		n/=10;
	}
	printf("%d",lastnum);
}

The first line is input, and the second line is output.

You can understand it if you are smart!

Guess you like

Origin blog.csdn.net/qq_52208569/article/details/109922505