C语言for循环的问题

来源:百度知道 编辑:UC知道 时间:2024/05/22 12:38:39
要编一个输入数字输出英文的程序
如:输入1024 输出one zero two four
我的代码入下:
// Num_Eng.cpp : Defines the entry point for the console application.
//

#include <stdafx.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>

int main(int argc, char* argv[])
{
int a=0;
int len;
int div;
int n;
int m;
int i=1;
strl num;
scanf("%d",&a);
itoa(a,num,10);
len=strlen(num);
for(i=1;i<=len-2;i++);
{
div=len-i+2;
m=int(pow(10,div));
n=a/m;
if(n==1)printf("one ");
else if(n==2)printf("two ");
else if(n==3)printf("three ");
else if(n==4)printf("four ");
else if(n==5)printf("five ");
else if(n==6)printf("six ");
else if(n==7)printf(&

我试了一下你的程序, 输入1024只能输出one. 但i还是从1开始的.
程序复杂了. 试试这个. 输入非数字字符才停止.

#include <stdio.h>

int main()
{
int ok=1;
char num[20], *p;
static char *numstr[]={"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
while (ok) {
printf("Input a number...");
scanf("%s",num);
for (p=num; *p; ++p) if (*p<'0' || *p>'9') ok=0;
if (ok) {
for (p=num; *p; ++p) printf("%s ", numstr[*p-'0']);
printf("\n");
}
}
return 0;
}

main()
{
char s[11][10]={"zero","one","two","three","four","five","six","seven","eight","nine","ten"};
long int x;
long i=0;
int j=0,v[100],t