zoukankan      html  css  js  c++  java
  • c语言419 在显示所输入的数值的所有约数之后,显示约数的个数

    1、原始程序

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

    2、while语句

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

    3、for语句

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

    4、do语句

    #include <stdio.h>
    
    int main(void)
    {
        int i = 1, j, cnt = 0;
        puts("please input an integer.");
        do
        {
            printf("j = "); scanf("%d", &j);
            if (j <= 0)
                puts("the range of j is > 0"); 
        }
        while (j <= 0);
        
        do
        {
            if (j % i == 0)
            {
                printf("%d\n", i);
                cnt++;
            }
            i++;
        }
        while (i <= j);
        printf("the number of divesor is %d\n", cnt);
        
        return 0;
    }
  • 相关阅读:
    Linq to OBJECT延时标准查询操作符
    LINQ to XML
    动态Linq(结合反射)
    HDU 1242 dFS 找目标最短路
    HDu1241 DFS搜索
    hdu 1224 最长路
    BOJ 2773 第K个与m互质的数
    ZOJ 2562 反素数
    2016 ccpc 杭州赛区的总结
    bfs UESTC 381 Knight and Rook
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14682998.html
Copyright © 2011-2022 走看看