C编写函数问题 高手救命

来源:百度知道 编辑:UC知道 时间:2024/09/28 09:34:25
写一个函数,接受一个四位数,输入如下信息。
如:
输入1900
输出1-9-0-0
用函数写,而且不能用指针~

//如果可以保证输入的是4位的:
void print(int n){
printf("%d-%d-%d-%d", n/1000, (n%1000)/100, (n%100)/10, n%10);
}

//也可以递归打印
void output(int n, bool first_level = true){
if(n <= 0) return;
output(n/10, false);
printf("%d", n%10);
if(!first_level)printf("-");
else printf("\n");
}
//调用的时候: output(1990);

//或者先打印到字符串
void conv(int num){
static char buf[20];
sprintf(buf, "%d", num);
for(int i=0; buf[i]; ++i){
if(i>0) printf("-");
printf("%c", buf[i]);
}
}

#include <stdio.h>

#define SIZE 5

void putout(char s[SIZE])
{
printf("%c-%c-%c-%c\n",s[0],s[1],s[2],s[3]);
}

int main()
{
char s[SIZE];
printf("Input a integer: \b");
gets(s);
putout(s);

r