Past review:
Find Sn=a+aa+aaa+aaaa+...n a, a is a number, and n represents the number of a
C language implements a simple game:
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:
If 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