c program for the reverse the digits

后端 未结 8 933
北恋
北恋 2021-01-07 11:27

I am looking for the C program for reverse the digits like below:

If i enter:

123456

Then the result would

8条回答
  •  北海茫月
    2021-01-07 12:06

    Here is a simple solution to this complex problem:

    #include 
    
    int main()
    {
        int ch;
        ch = getchar();
        if (ch != '\n') {
            main();
            printf("%c", ch);
        }
    }
    


    A new version that outputs the newline:

    #include 
    #include 
    
    static void newline(void)
    {
        printf("\n");
    }
    
    int main()
    {
        int ch;
        ch = getchar();
        if (ch != '\n') {
            main();
            printf("%c", ch);
        } else {
            atexit(newline);
        }
    }
    

提交回复
热议问题