用空格分隔数字
分隔五位整数中的数字
写一个程序,对于一个给定的五位数,把这个数分成几个独立的数字,然后打印出彼此相隔4个空格的数字。
[提示:使用整数除法和余数运算的组合。]
例如,如果用户输入42139,程序应该打印出来
4 2 1 3 9
/*
Name:Separating Digits in an Integer.c
Author:祁麟
copyright:BJTU | school of software class2004
Date:2020/9/30
Description:separates the number into its individual digits and prints the digits separated frome one another by 4 spaces each.
*/
#include <stdio.h>
int main()
{
int n,a,b,c,d,e;
scanf ("%d",&n);
a=n/10000;
b=(n-a*10000)/1000;//提供其中一种思路,也可通过取余数来编写
c=(n-a*10000-b*1000)/100;
d=(n-a*10000-b*1000-c*100)/10;
e=n-a*10000-b*1000-c*100-d*10;
printf ("%d\t %d\t %d\t %d\t %d\t",a,b,c,d,e);
return 0;
}
更多推荐
C语言入门 -- 用空格分隔数字(2020/12/9)
发布评论