PTA作业 输出整数各位数字

#include<stdio.h>
#include<math.h>
int main()
{
    int num,i;//先要知道位数
    int t=0;
    long int n,f;
    scanf("%ld",&n);
    f=n;
    if(n==0)
    {
        printf("0 ");//,尽管是0,也不要忘记数字后面的空格
    }else{
        do
        {
            n=n/10;
            t++;
        }while(n>0);
        while(t>0)
        {
            i=pow(10,t-1);
            printf("%d ",f/i);
            t--;
            f=f%i;
        }
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/jiangzenghui/p/12466436.html