用C语言将不大于999999的数字转化为英文,如1234表示为one thousand two hundred and thirty four,给出代码
时间: 2023-03-15 20:15:42 浏览: 86
代码如下:#include<stdio.h>
#include<string.h>int main()
{
char str[100];
int num,len; printf("请输入一个不大于999999的数字:");
scanf("%d", &num); sprintf(str, "%d", num);
len = strlen(str);
if (len == 6)
{
printf("%s thousand ",&str[0]);
printf("%s hundred ",&str[1]);
printf("and %s",&str[2]);
}
else if (len == 5)
{
printf("%s thousand ", &str[0]);
printf("and %s", &str[1]);
}
else if (len == 4)
{
printf("%s thousand ", &str[0]);
}
else if (len == 3)
{
printf("%s hundred ", &str[0]);
printf("and %s", &str[1]);
}
else if (len == 2)
{
printf("and %s", &str[0]);
}
else if (len == 1)
{
printf("%s", &str[0]);
} return 0;
}