first demo

#include 
//输入年龄 20
//your age is twenty; 

int main(){
    int age = 0;
    
    //保存个位数 21%10 = 1 
    char* gewei[] = {"","one","two","three","four","five","six","seven","eight","nine"}; 
    //保存10-19
    char* temp[] = {"ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
    //保存十位 
    char* shiwei[] = {"twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"}; 
    
    printf("请输入年龄:");
    scanf("%d", &age);
    
    char *name;//保存每次取出的字符串 
    if(age < 10){
        //直接访问各位数数组
        name = gewei[age];
    }else if(age >= 10 && age <= 19){
        //获取个位数  
        int index = age % 10;
        name = temp[index];
    } else{
        //获取个位数 
        int g = age % 10; 
        //获取十位数 
        int s = age / 10;
        //取出对应的单词
        int sString = shiwei[s-2];
        int gString = gewei[g];
        
        printf("your age is %s-%s\n"
        ,sString,gString); 
        
        //程序还未运行完毕就提前结束
        return 0; 
    } 
    
    printf("your age is %s\n",name);
     
    return 0;
}

你可能感兴趣的:(first demo)