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;
    }
  • 相关阅读:
    sqlplus edit 方式设置成vi
    oracle minus union intersect
    子查询中可以包含order by 子句--(在from里面)
    Linux 7 Ansible 初学 一个简单的 playbook 学习 yum 模块
    Linux 7 Ansible 初学 配置被控制机器的 YUM 源
    Linux 7 安装 Ansible 并作基本的配置
    Linux 7 安装开发工具包 Development Tools
    Linux 7.0 安装 mariadb 数据库及初始化,创建数据库,创建用户
    Linux bash初学 if语句
    Linux bash初学 case语句
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14681312.html
Copyright © 2011-2022 走看看