C语言实验——分割整数
Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic
Problem Description
从键盘输入一个长整数(不超过10位),从高位开始逐位分割并输出。
Input
正整数n,不含前导零。
Output
分割的整数序列,各整数之间用空格格开。
注意,最后一个数字后面没有空格!
Example Input
654321
Example Output
6 5 4 3 2 1
Hint
Author
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a[10];
int n,i=0,j;
scanf("%d",&n);
while(n)
{
a[i++] = n % 10;//a[i++]表示先对a[i]赋值,然后i变为i++;
n = n / 10;
}
for(j = i-1;j >= 0;j--)//分离的时候,个位数存放在前面,故逆序输出
{
if(j==0)printf("%d\n",a[j]);
else printf("%d ",a[j]);
}
return 0;
}