C语言编写程序, 提示从键盘输入一个小于1000的正整数,并读入该值,然后输出用语言描述的该整数值

C语言编写程序,
提示从键盘输入一个小于1000的正整数,并读入该值,然后输出用语言描述的该整数值。例如,941,程序将输出
字符串"Nine hundred and forty one".

1、首先,点击桌面上的软件,打开c语言编程软件,点击右上角的【文件】,【新建】。

2、再点击【文件】,选择下方C++ Source File。文件名必须以.c结尾,最后点击【确定】。

3、输入代码://显示并确认输入的整数值#include<stdio.h>int main(void){ int no; printf("请输入一个整数值:"); scanf("%d",&no)printf("您输入的是%d.\n",no);  return 0;}。

4、编写好以后:点击1的图标,进行编译,查找错误。点击2进行连接。点击3进行运行。

5、点击运行后,输入一个整数值,再按回车键,这样就完成了。

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-10-02
#include "stdio.h"
void aa(int k)//个位数字或者百位数字
{
switch(k)
{case(1):printf("one ");break;
case(2):printf("two ");break;
case(3):printf("three ");break;
case(4):printf("four ");break;
case(5):printf("five ");break;
case(6):printf("six ");break;
case(7):printf("seven ");break;
case(8):printf("eight ");break;
case(9):printf("nine ");break;
default:;}
}
void aaa(int i,int j)//特殊情况
{
switch(10*i+j)
{
case(10):printf("ten");break;
case(11):printf("eleven");break;
case(12):printf("twelve");break;
case(13):printf("thirteen");break;
case(14):printf("fourteen");break;
case(15):printf("fifteen");break;
case(16):printf("sixteen");break;
case(17):printf("seventeen");break;
case(18):printf("eighteen");break;
case(19):printf("nineteen");break;
}
}
void x(int l)//十位数字
{
switch(l)
{
case(2):printf("twenty ");break;
case(3):printf("thirty ");break;
case(4):printf("forty ");break;
case(5):printf("fifty ");break;
case(6):printf("sixty ");break;
case(7):printf("seventy ");break;
case(8):printf("eighty ");break;
case(9):printf("ninty ");break;
default:;
}
}
void fun(int a,int b,int c)
{
if(a>0){aa(a);printf("hundred and ");}

if(b==1)aaa(b,c);
if(b>1&&b<=9){x(b);aa(c);}
if(b==0)aa(c);
printf("\n");
}
void main()
{
int a,i,j,k;//a是用来存储数的,i是用来存储百位,j是用来存储十位,k是用来存储个位
printf("请输入数字(小于1000的正整数)\n");
scanf("%d",&a);
if(a>=1000&&a<0)
printf("输入错误\n");
else
{i=a/100;
j=a/10%10;
k=a%10;
fun(i,j,k);
}
}追答

貌似没有上面的好

#include "stdio.h"
#include "string.h"
void daxie(char p[])//首字母大写
{
p[0]-=32;
}
void aa(int k,char r[])//个位数字或者百位数字
{
char *t;
switch(k)
{
case(1):{t="one ";strcat(r,t);}break;
case(2):{t="two ";strcat(r,t);}break;
case(3):{t="three ";strcat(r,t);}break;
case(4):{t="four ";strcat(r,t);}break;
case(5):{t="five ";strcat(r,t);}break;
case(6):{t="six ";strcat(r,t);}break;
case(7):{t="seven ";strcat(r,t);}break;
case(8):{t="eight ";strcat(r,t);}break;
case(9):{t="nine ";strcat(r,t);}break;
default:;
}
}
void aaa(int i,int j,char o[])//特殊情况
{
char *w;
switch(10*i+j)
{
case(10):{w="ten";strcat(o,w);}break;
case(11):{w="eleven";strcat(o,w);}break;
case(12):{w="twelve";strcat(o,w);}break;
case(13):{w="thirteen";strcat(o,w);}break;
case(14):{w="fourteen";strcat(o,w);}break;
case(15):{w="fifteen";strcat(o,w);}break;
case(16):{w="sixteen";strcat(o,w);}break;
case(17):{w="seventeen";strcat(o,w);}break;
case(18):{w="eighteen";strcat(o,w);}break;
case(19):{w="nineteen";strcat(o,w);}break;
}
}
void x(int l,char y[])//十位数字
{
char *u;
switch(l)
{
case(2):{u="twenty ";strcat(y,u);}break;
case(3):{u="thirty ";strcat(y,u);}break;
case(4):{u="forty ";strcat(y,u);}break;
case(5):{u="fifty ";strcat(y,u);}break;
case(6):{u="sixty ";strcat(y,u);}break;
case(7):{u="seventy ";strcat(y,u);}break;
case(8):{u="eighty ";strcat(y,u);}break;
case(9):{u="ninty ";strcat(y,u);}break;
default:;
}
}
void fun(int a,int b,int c,char s[])
{
char *w,*e;
if(a>0){aa(a,s);w="hundred ";strcat(s,w);if(b!=0||c!=0){e="and ";strcat(s,e);}}
if(b==1)aaa(b,c,s);
if(b>1&&b=1000&&a<0)
printf("输入错误\n");
else
{i=a/100;
j=a/10%10;
k=a%10;
fun(i,j,k,m);
daxie(m);
puts(m);
}
}
改完之后就完美了😊

还有一个错误,在主函数if(a>=1000&&a<0),不应该用与,用或!!打错了!

追问

SO嘎!

谢谢你

追答

没事

本回答被提问者和网友采纳
第2个回答  2015-02-17

代码粘贴格式会变了,所以用附件上传,测试数据如下图,有问题可以追问。

 

追问

唔,谢谢您,

相似回答