用CY语言写一个代码:输入一个小于5位的正整数,分别输出它的位数及其逆序打印出各位数字
时间: 2024-04-11 11:27:56 浏览: 11
Sure! Here's a C program that takes an input less than 5 digits and outputs its number of digits and the reverse order of its digits:
```c
#include <stdio.h>
int main() {
int number, temp, digit, reverse = 0;
int count = 0;
printf("Enter a positive integer less than 5 digits: ");
scanf("%d", &number);
// Calculate the number of digits
temp = number;
while (temp != 0) {
temp /= 10;
count++;
}
// Print the number of digits
printf("Number of digits: %d\n", count);
// Print the reverse order of the digits
temp = number;
while (temp != 0) {
digit = temp % 10;
reverse = reverse * 10 + digit;
temp /= 10;
}
printf("Reverse order: %d\n", reverse);
return 0;
}
```
You can compile and run this program to get the desired output.