//输入一个四位数,要求输出该四位数的每一个数字,每个数字之间隔一个空格(利用函数实现)
代码实现:
//例如输入1997,输出1 9 9 7
#include<stdio.h>
//函数声明与定义
void Print(int x)
{
//临时变量,用来存储每一个位数上的数字
int t;
//除数
int t1 = 1000;
//循环
while(x)
{
//拿到每一位数
t = x/t1;
//打印每一位数
printf("%d ",t);
//拿到除去上一位数字的剩下的数字
x%=t1;
//除数每次少十倍
t1/=10;
}
}
//主函数
int main()
{
int n;
scanf("%d",&n);
//函数调用
Print(n);
return 0 ;
}
程序运行结果:

&spm=1001.2101.3001.5002&articleId=154351059&d=1&t=3&u=954322e831c44d0ea8303e3316de2d3b)
4094

被折叠的 条评论
为什么被折叠?



