C语言实验——分割整数
Time Limit: 1000MS Memory Limit: 65536KB
Problem Description
从键盘输入一个长整数(不超过10位),从高位开始逐位分割并输出。
Input
正整数n,不含前导零。
Output
分割的整数序列,各整数之间用空格格开。
注意,最后一个数字后面没有空格!
注意,最后一个数字后面没有空格!
Example Input
654321
Example Output
6 5 4 3 2 1
Hint
Author
参考代码
#include<stdio.h>
int main()
{
int a[10];
long n;
int i;
scanf("%d",&n);
for(i = 0; i < 10; i++)
{
a[i] = n % 10;
n = n / 10;
if(n == 0)
break;
}
n = i;
for(i = n; i >= 0; i--)
{
if(i == 0)
printf("%d\n",a[i]);
else
printf("%d ",a[i]);
}
return 0;
}