zoukankan      html  css  js  c++  java
  • c语言 411 逆向输出输入的整数值(同时输出原始数据)

    1、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("%d's reversed result is: ", i);
        while (i > 0)
        {
            printf("%d", i % 10);
            i /= 10;
        }
        putchar('\n');
        return 0;
    }
    #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);
        
        return 0;
    }

    2、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;
    }
    #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;
    }

    3、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;
    }
    #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;
    }
  • 相关阅读:
    opengl一些基础函数-- 缓冲区
    width = 100%??
    设置scrollTop无效
    es5与es6继承区别
    immutable-treeUtils树的理解
    react 事件绑定
    es-6 class
    es6-Module语法
    es6--set数组去重,Map数据结构
    promise对象
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14677699.html
Copyright © 2011-2022 走看看