在c语言中 如何将1,2,3,变成1st,2nd,3rd;求完整步骤,谢谢!

输入为多个很小的正整数,当输入为0时表示输入结束,
输出为多行,每行对应一个输入数字的序数表。
Sample Input
1 2 3 4 5 10 11 12 13 14 0
Sample Output
1st 2nd 3rd 4th 5th 10th 11st 12nd 13rd 14th

第1个回答  2015-04-28
#include<stdio.h>


char *ch[5] = {"", "st" , "nd", "rd", "th"};


int main(){

        int tmp;
        int last_num;

        while(1){
                scanf("%d", &tmp);
                if(tmp == 0)
                        break;
                else{
                        last_num = tmp % 10;
                        if(last_num > 4)
                                last_num = 4;
                        printf("%d%s ", tmp, ch[last_num]);
                }
        }
        return 0;



}

追问

10不行啊,10编译不出

追答

if(last_num > 4 || last_num == 0)

本回答被网友采纳
第2个回答  2015-04-28
这个应该不难,先拿数组中的数对10求余得到各位上的数,然后再根据各位上的数判断到底是st,nd,rd还是th,先不给你写了,你自己试试吧!搞不得再问