zoukankan      html  css  js  c++  java
  • c语言 411 将输入的正整数进行逆向输出

    将输入的正整数进行逆向输出。

    1、while语句

    #include <stdio.h>
    
    int main(void)
    {
        int i, j = 0;
        puts("please input an integer.");
        do
        {
            printf("i = "); scanf("%d", &i);
            if (i <= 0)
                puts("the range of i is : > 0 ");
        }
        while (i <= 0);
        
        printf("the reversed result of %d is: ", i);
        while (i > 0)
        {
            j = j * 10 + i % 10;
            i /= 10;
        }
        printf("%d\n", j);
        putchar('\n');
        
        return 0;
    }

    2、while语句

    #include <stdio.h>
    
    int main(void)
    {
        int i;
        puts("please input an integer.");
        do
        {
            printf("i = "); scanf("%d", &i);
            if (i <= 0)
                puts("the range of i is : > 0 ");
        }
        while (i <= 0);
        
        printf("the reversed result of %d is: ", i);
        while (i > 0)
        {
            printf("%d", i % 10);
            i /= 10;
        }
        putchar('\n');
        
        return 0;
    }

    3、for语句

    #include <stdio.h>
    
    int main(void)
    {
        int i, j = 0;
        puts("please input an integer.");
        do
        {
            printf("i = "); scanf("%d", &i);
            if (i <= 0)
                puts("the range of i is : > 0 "); 
        }
        while (i <= 0);
        
        printf("the reversed result of %d is: ", i);
        for (i; i > 0; i /= 10)
        {
            j = j * 10 + i % 10;
        }
        printf("%d\n", j);
        
        return 0;
    }

    4、for语句

    #include <stdio.h>
    
    int main(void)
    {
        int i;
        puts("please input an integer.");
        do
        {
            printf("i = "); scanf("%d", &i);
            if (i <= 0)
                puts("the range of i is : > 0 ");
        }
        while (i <= 0);
        
        printf("the reversed result of %d is: ", i);
        for (i; i > 0; i /= 10)
        {
            printf("%d", i % 10);
        }
        putchar('\n');
        
        return 0;
    }

    5、do语句

    #include <stdio.h>
    
    int main(void)
    {
        int i, j = 0;
        puts("please input an integer.");
        do
        {
            printf("i = "); scanf("%d", &i);
            if (i <= 0)
                puts("the range of i is : > 0 ");
        }
        while (i <= 0);
        
        printf("the reversed result of %d is: ", i);
        do
        {
            j = j * 10 + i % 10;
            i /= 10;
        }
        while (i > 0);
        printf("%d\n", j);
        
        return 0;
    }

    6、do语句

    #include <stdio.h>
    
    int main(void)
    {
        int i;
        puts("please input an integer.");
        do
        {
            printf("i = "); scanf("%d", &i);
            if (i <= 0)
                puts("the range of i is: > 0 ");
        }
        while (i <= 0);
        
        printf("the reversed result of %d is: ", i);
        do
        {
            printf("%d", i % 10);
            i /= 10;
        }
        while (i > 0);
        putchar('\n');
        
        return 0;
    }
  • 相关阅读:
    如何选择Html.RenderPartial和Html.RenderAction
    [转]使用 HTML5 WebSocket 构建实时 Web 应用
    基于.NET平台常用的框架整理
    0303
    XMLHTTP
    0120如何合并两个使用 System.Xml 使用 Visual C#.NET 的 XML 文档中的数据
    后台动态创建datatable0115
    笔记1126ASP.NET面试题(转)
    笔记1015
    数组与ARRAYLIST的关系与区别(转)
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14681312.html
Copyright © 2011-2022 走看看