请帮忙找找错误,谢谢

2301_80439625 2023-11-19 20:32:02

 

英文翻译自然数

题目描述:按常规英文输出1000以内自然数的英文读法。
 

输入:每个测试输入包含 1 个测试用例,给出正整数 n(0<= n <1000)

输出:输出占一行:如果 0<= n <1000, 用规定的格式输出 n,所有英文单词小写,最后一个单词后无字符;否则输出ERR。

 

#include<stdio.h>

int main(){

int x;

scanf("%d",&x);

if(x==0) printf("zero");

if(x>0&&x<1000){

char*a[19]={"one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thriteen","forteen","fifteen","sixteen","seventeen","eighty","nineteen"};

char*b[8]={"twenty","thrity","forty","fifty","sixty","seventy","eighty","ninety"};

if(x/100!=0){ printf("%s",a[(x/100-1)]);

 printf(" hundred");

if(x%100<20) printf(" and %s",a[(x%100-1)]) ;

if(x%100>=20) printf(" and %s-%s",b[(x%100/10-2)],a[(x%100%10-1)]);}

if(x/100==0){

if(x<20) printf("%s",a[(x-1)]);

if(x>=20) printf("%s-%s",b[(x%10-2)],a[(x%10%10-1)]);

}}

if(x>=1000||x<0) printf("ERR");}

...全文
111 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复

#include<stdio.h>
void main()
{
char *Eng1[20]={"zero","one","two","three","four","five","six","seven",
"eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen",
"sixteen","seventeen","eighteen","nineteen"};
char *Eng2[8]={"twenty","thirty","fourty","fifty","sixty","seventy","eighty","ninety"};
int num;
printf("请输入数字: ");
scanf("%d",&num);
printf("对应的英文为: ");
if(num>=0&&num<=19)
printf("%s\n",Eng1[num]);
else if(num<100)
{
int s,y;
s=num/10;
y=num%10;
printf("%s %s\n",Eng2[s-2],Eng1[y]);
}
else if(num<1000)
{
int b,s,y;
b=num/100;
y=num%100;
if(y>9)
{
s=(num%100)/10;
y=(num%100)%10;
if(y==0)
printf("%s hundred and %s\n",Eng1[b],Eng2[s-2]);
else
printf("%s hundred and %s %s\n",Eng1[b],Eng2[s-2],Eng1[y]);
}
else
printf("%s hundred and %s\n",Eng1[b],Eng1[y]);
}
}

  • 打赏
  • 举报
回复

#include <stdio.h>

int main() {
int x;

scanf("%d", &x);

if (x < 0 || x >= 1000) {
    printf("ERR");
} else if (x == 0) {
    printf("zero");
} else {
    char *a[19] = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven",
                   "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
    char *b[8] = {"twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};

    if (x / 100 != 0) {
        printf("%s hundred", a[x / 100 - 1]);

        if (x % 100 != 0) {
            printf(" and ");

            if (x % 100 < 20) {
                printf("%s", a[x % 100 - 1]);
            } else {
                printf("%s-%s", b[x % 100 / 10 - 2], a[x % 100 % 10 - 1]);
            }
        }
    } else {
        if (x < 20) {
            printf("%s", a[x - 1]);
        } else {
            printf("%s-%s", b[x / 10 - 2], a[x % 10 - 1]);
        }
    }
}

return 0;

}

69,112

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧