c++输入整数输出对应中文的题目怎么解
预期结果:请帮忙解一下这题,如果能附加注释是最好的了,谢谢,新手上路
Problem Description
给出在范围内的整数数字,你能把对应的中文写出来吗?
Input
第一行输入一个T (T <= 20),后面每行一个数字,题目保证数字是。
Output
第一行输入一个T (T <= 20),后面每行一个数字,题目保证数字是。
Sample Input
5
1
22
3
4
100
Sample Output
一
二十二
三
四
一百 #include <stdio.h>
int main(){
int num;
char* digit = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十"}; //存入所有中文字符,方便等下输出
scanf("%d", &num);
if(num <= 10) printf("%s", digit); // 当整数小于等于 10(1, 2, 3 .... 10)
else if(num < 20) printf("十%s", digit); // 当整数小于 20(11, 12, 13 .... 19)
else if(num < 100){ // 当整数小于 100(20, 21, 22 .... 99)
int a = num%10; // 取个位数
int b = (num - a)/10; // 取十位数
if(!(a)) printf("%s%s", digit, digit); // 当个位数为 0
else printf("%s%s%s", digit, digit, digit); // 当个位数不是 0
}
else printf("一百"); // 当整数为 100 整
return 0;
}12
十二
9
九
34
三十四
100
一百 file:///C:/Users/%E9%98%BF%E9%A3%9E%E5%93%A5/Desktop/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20211016202139.png
你好能帮我再看看吗,拿去Oj上提交显示的是Compilation Error 编译错误,谢谢您了
傻眼貓咪 发表于 2021-10-16 09:21
file:///C:/Users/%E9%98%BF%E9%A3%9E%E5%93%A5/Desktop/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20211016202139.png
你好,能再帮我看一下吗,我提交到OJ上,是面显示Compilation Error 编译错误,谢谢了,上面是我发给您 的图片地址 提交习题最好自己做比较好,如果只是不明白可以发问不明白部分,不是全部哦{:5_109:} 傻眼貓咪 发表于 2021-10-16 09:21
上面给出的是这样子的信息
2_37884_3662015_24779.c: In function 'main':
2_37884_3662015_24779.c:5:91: error: expected expression before '/' token
char* digit = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十"}; //存入所有中文字符,方便等下输出
^
2_37884_3662015_24779.c:5:91: error: stray '\264' in program
2_37884_3662015_24779.c:5:91: error: stray '\346' in program
2_37884_3662015_24779.c:5:91: error: stray '\310' in program
2_37884_3662015_24779.c:5:91: error: stray '\353' in program
2_37884_3662015_24779.c:5:91: error: stray '\313' in program
2_37884_3662015_24779.c:5:91: error: stray '\371' in program
2_37884_3662015_24779.c:5:91: error: stray '\323' in program
2_37884_3662015_24779.c:5:91: error: stray '\320' in program
2_37884_3662015_24779.c:5:91: error: stray '\326' in program
2_37884_3662015_24779.c:5:91: error: stray '\320' in program
2_37884_3662015_24779.c:5:91: error: stray '\316' in program
2_37884_3662015_24779.c:5:91: error: stray '\304' in program
2_37884_3662015_24779.c:5:91: error: stray '\327' in program
2_37884_3662015_24779.c:5:91: error: stray '\326' in program
2_37884_3662015_24779.c:5:91: error: stray '\267' in program
2_37884_3662015_24779.c:5:91: error: stray '\373' in program
2_37884_3662015_24779.c:5:91: error: stray '\243' in program
2_37884_3662015_24779.c:5:91: error: stray '\254' in program
2_37884_3662015_24779.c:5:91: error: stray '\267' in program
2_37884_3662015_24779.c:5:91: error: stray '\275' in program
2_37884_3662015_24779.c:5:91: error: stray '\261' in program
2_37884_3662015_24779.c:5:91: error: stray '\343' in program
2_37884_3662015_24779.c:5:91: error: stray '\265' in program
2_37884_3662015_24779.c:5:91: error: stray '\310' in program
2_37884_3662015_24779.c:5:91: error: stray '\317' in program
2_37884_3662015_24779.c:5:91: error: stray '\302' in program
2_37884_3662015_24779.c:5:91: error: stray '\312' in program
2_37884_3662015_24779.c:5:91: error: stray '\344' in program
2_37884_3662015_24779.c:5:91: error: stray '\263' in program
2_37884_3662015_24779.c:5:91: error: stray '\366' in program
2_37884_3662015_24779.c:8:45: error: expected expression before '/' token
if(num <= 10) printf("%s", digit); // 当整数小于等于 10(1, 2, 3 .... 10) 傻眼貓咪 发表于 2021-10-16 20:56
提交习题最好自己做比较好,如果只是不明白可以发问不明白部分,不是全部哦
嗯嗯好的谢谢您了{:5_109:}
页:
[1]