View Code of Problem 77

//写一函数,输入一个四位数字,要求输出这四个数字字符,
//但每两个数字间空格。如输入1990,应输出"1 9 9 0"。
#include<stdio.h>
#include<math.h>
int main(){
	int n;
	scanf("%d",&n);
	int mask=1;
	int t=n;
	int count=0;
	while(t>9){
		t=t/10;
		count++;
	}
	int i;
	for(i=0;i<count;i++){
		mask=mask*10;
	}
//	printf("%d",mask);
	int d;
	while(mask>0){
		d=n/mask;
		n=n%mask;
		if(mask>9){
			printf("%d ",d);
		}else{
			printf("%d",d);
		}	
		mask=mask/10;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 77