分割整數(迴圈結構)
阿新 • • 發佈:2019-02-17
Description
給出一個正整數(positive integer)(不超過10位),從高位開始逐位分割並輸出。注:用陣列者判cheat,且封號一週。
Input
測試資料有多行,每行是一個正整數 n ,不含前導零。
Output
對每個測試輸出一行結果:分割後的整數序列,每位數之後跟一個空格。
Sample Input
654321
1
Sample Output
6 5 4 3 2 1
1
#include <stdio.h>
#include <math.h>
int main ()
{
long long i,ss,l=1;
long long temp=0;
while (scanf("%lld",&i)!=EOF)
{ l=i;
ss=i;
temp=0;
while(ss)
{
ss=ss/10;
temp++;
}
for(long long j=temp-1;j>0;j--)
{
ss=i/(long long )pow(10,j);
i=i-ss*(long long )pow(10,j);
printf ("%lld ",ss);
}
printf("%lld \n",l%10);
}
return 0;
}