如何用C语言编出 读入一个五位数,分割该数各位上的数并将分割的数字以间隔三

2025-05-20 22:10:35
推荐回答(2个)
回答(1):

main( )
{
long a, b, c, d, e, x;
scanf("%ld", &x);
a = x / 10000; /* 分解出万位 */
b = x % 10000 / 1000; /* 分解出千位 */
c = x % 1000 / 100; /* 分解出百位 */
d = x % 100 / 10; /* 分解出十位 */
e = x % 10; /* 分解出个位 */
if (a!=0) printf("there are 5, %ld %ld %ld %ld %ld\n", e, d, c, b, a);
else if (b!=0) printf("there are 4, %ld %ld %ld %ld\n", e, d, c, b);
else if (c!=0) printf(" there are 3, %ld %ld %ld\n", e, d, c);
else if (d!=0) printf("there are 2, %ld %ld\n", e, d);
else if (e!=0) printf(" there are 1, %ld\n", e);
}

回答(2):

#include
void fun(int num)//递归方法
{
    if(num/10==0)
    {
        printf("%-4d",num%10);
        return;
    }
    fun(num/10);
    printf("%-4d",num%10);
    return;
}
int main()
{
    printf("输入5位数:\n");
    int n;
    scanf("%d",&n);//没有做输入检查
    fun(n);
    return 0;
}