我用wandbox测试了一下他的代码,在gcc c语言中代码是不通过的,在gcc c++语言中代码可以通过,不过警告一大堆
最严重的是char * key[]=
最严重的是char * key[]=
把学习时间浪费在混坛上是傻瓜行为,更何况自己的水平连一两都没到。
#include <stdio.h> #include <stdlib.h> #include <math.h> int main(void) { int count=0; char * key[]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"}; char num[1000]; scanf("%s",num); int index=1; int gewei = 0; for(int i=0;num[i]!='\0';i++) { count=count+((int)num[i]-48); if(count/index>0) { gewei++; index *=10; } } if(count==0) { printf("ling"); } else { for(int i=gewei;i;i--) { int d=count/pow(10,i-1); printf("%s",key[d]); count = count-d*pow(10,i-1); if(count<=0) { printf(""); } else { printf(" "); } } } return 0; }
对呀,这样改警告就没啦 #include <stdio.h> #include <stdlib.h> #include <math.h> int main(void) { int count=0; char key[][100]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"}; char num[1000];int a[100]; scanf("%s",num); int index=1; int gewei = 0; for(int i=0;num[i]!='\0';i++) { count=count+((int)num[i]-48); if(count/index>0) { gewei++; index *=10; } } for(int i=gewei;i!=0;--i) { a[i]=count%10; count= count/10; } for(int i=1;i<=gewei;++i) { printf("%s ",key[a[i]]); }printf("%c",8); return 0; }
#include <stdio.h> #include <stdlib.h> #include <math.h> int main(void) { int count=0; char * key[]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"}; char num[1000]; scanf("%s",num); int index=1; int gewei = 0; for(int i=0;num[i]!='\0';i++) { count=count+((int)num[i]-48); if(count/index>0) { gewei++; index *=10; } } for(int i=gewei;i>0;i--) { int d=count/pow(10,i-1); printf("%s",key[d]); count = count-d*pow(10,i-1); if(i>1) { printf(" "); } } system("pause"); return 0; }