C language: Given a positive integer with no more than 5 digits, request: find out how many digits it is, output each digit separately, and output each digit in reverse order, for example, the original number is 321, and 123 should be output

Past review:

Find Sn=a+aa+aaa+aaaa+...n a, a is a number, and n represents the number of a

C language: Two table tennis teams compete with three players each. Team A has three players a, b, and c, and team B has three players x, y, and z. play list

C language: Yang Hui triangle (using two-dimensional array)

C language implements a simple game:

 guess the number game

 Backgammon (with source code)

 String output in reverse order

​​​​​​ Dynamic programming and greedy algorithm summary

Topic: Given a positive integer with no more than 5 digits, request: find out how many digits it is, output each digit separately, and output each digit in reverse order, for example, the original number is 321, and 123 should be output

Idea: Construct a loop, take the remainder of the input number, and output the remainder in turn, and then perform the divisor operation on it, and then perform the remainder output operation on the obtained quotient.

For example, 321 takes the remainder of 10 as 1, and outputs 1.

321 divided by 10 quotient 32 32 to 10 take remainder is 2 output 2

When 32 is divided by 10, the quotient 3 is 3, and the remainder of 3 to 10 is 3, and the output is 3

result 123

Code example:

int main()
{
	int num;
	int temp = 0;
	printf("请输入数字:");
	scanf("%d", &num);
	while (num >= 100000)
	{
		printf("输入有误,请重新输入:");
		scanf("%d", &num);
	}
	if (num > 0 && num < 10)
	{
		printf("他是一位数:\n");
		printf("%d\n", num);
		printf("逆序输出:");
	}
	else if (num > 9 && num < 100)
	{
		printf("他是两位数:\n");
		printf("%d\n", num);
		printf("逆序输出:");
	}
	else if (num > 99 && num < 1000)
	{
		printf("他是三位数:\n");
		printf("%d\n", num);
		printf("逆序输出:");
	}
	else if (num > 999 && num < 10000)
	{
		printf("他是四位数:\n");
		printf("%d\n", num);
		printf("逆序输出:");
	}
	else if (num > 9999 && num < 100000)
	{
		printf("他是五位数:\n");
		printf("%d\n", num);
		printf("逆序输出:");
	}
	while(num > 0 && num < 100000)
	{
		temp =  num % 10;
		printf("%d", temp);
		num = num / 10;
	}	
	return 0;
}

Program running:

watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAb29yaWs=,size_20,color_FFFFFF,t_70,g_se,x_16If you can help, click like and leave!

                                                            The harder you work, the luckier you get, come on!

If you know the above method, you can transfer to my blog for any number

C language: Given a positive number, find out how many digits it has, output each digit separately, and output each digit in reverse order, for example, the original number is 321, and 123 should be output_oorik's blog

 

 

 

Guess you like

Origin blog.csdn.net/weixin_51609435/article/details/120640853