苏拉玛秘密通信任务:编写一个函数,输入一个4为数,输出它,但2个数字之间要有空格,如2006,输出2 0 0 6,请高手赐教!!

来源:百度文库 编辑:高校问答 时间:2024/04/30 15:34:21
是C的,忘记说明了,不好意思!!要写函数的!

建议你用C++啊 不过你要C,就给你C语言的
#include<stdio.h>
int main()
{
char* a = new char[5] ;
scanf("%s",a);
for(int i=0 ; i<4 ; i++)
printf("%c ",a[i]) ;
printf("\n");
}

给出delphi的做法

function Trans(ANumber:Integer):string
var
AString:string;
i:Integer;
begin
result:='';
AString:=IntToStr(ANumber);
for i:=1 to length(AString) do
begin
result:=result+AString[i]+' ';
end;
result:=trim(result);
end;

#include<stdio.h>
main()
{
int a,b,c,d;
scanf("%1d%1d%1d%1d",&a,&b,&c,&d);
printf("%d %d %d %d",a,b,c,d);
}


c++的算法:
#include "iostream"
using namespace std;
main()
{
int a,b,c,d;
cin>>a>>b>>c>>d;
count<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
}

lwjt的程序有创意

如果不嫌麻烦
用replace函数逐位替换
或者字符串截取后在每位后面添加一空格