05-2. read numbers (15)

Source: Internet
Author: User
Tags case statement

Enter an integer and the pinyin corresponding to each digit. When the integer is negative, the word "Fu" is output first. The 10 digits correspond to the following pinyin:

0: ling1: yi2: er3: san4: si5: wu6: liu7: qi8: ba9: jiu

Input Format:

Enter an integer in a row, for example:1234.

Tip: integers include negative, zero, and positive.

Output Format:

Output the pinyin corresponding to this integer in one row. the pinyin characters of each number are separated by spaces. There is no final space at the end of the line. For exampleyi er san si.

Input example:

-600

Output example:

fu liu ling ling

 

Note: You can also use the switch-case statement to implement this question.

#include "stdio.h"int main(){    int N,t,p,n=0;    scanf("%d",&N);    t=N;    if(N<0)    {        printf("fu ");        N=-N;    }    if(N==0)    {        printf("ling");        goto out;    }    p=N;    while(N>9)    {        N/=10;        n++;    }    int x=1;    while(n>0)    {        x*=10;        n--;    }    int z;    do{        z=p/x;        if(x>0)        {            p%=x;                //x!=0        }        x/=10;        if(z==0)        {            printf("ling");        }        else if(z==1)        {            printf("yi");        }        else if(z==2)        {            printf("er");        }        else if(z==3)        {            printf("san");        }        else if(z==4)        {            printf("si");        }        else if(z==5)        {            printf("wu");        }        else if(z==6)        {            printf("liu");        }        else if(z==7)        {            printf("qi");        }        else if(z==8)        {            printf("ba");        }        else        {            printf("jiu");        }        if(x>0)        {            printf(" ");        }    }while(x>0);out:        return 0;}

05-2. read numbers (15)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.