zoukankan      html  css  js  c++  java
  • (for述句)韩信点兵中的最大值问题

    #include <stdio.h>
    int main()
    {
    
    
    int max;
    printf("MAX = ");
    scanf("%d", &max);
    int number;
    int answer = 0;
    for (number = max;number >= 1 && answer == 0; --number)
    {
        if (number%3 == 2 && number%5 == 3 && number%7 == 2)
        {
            answer = number;
        }
    }
    if (answer != 0)
    {
      printf("%d
    ",answer) ;
    }
    
    return 0;
    }

     韩信点兵找第三个小的练习

    #include <stdio.h>
    int main()
    {
        int count = 0;
        int number;
        for (number = 1; number <= 1000 && count <3;++number)
        {
            if (number%3 == 2 && number%5 == 3 && number%7 ==2)
            {
                ++count;
                if (count == 3)
                {
                    printf("%d", number);
                }
            }
        }
        return 0;
    }

     10.6质数判断练习

    1.

    #include <stdio.h>
    int main()
    {
        int N;
        printf("N = ");
        scanf("%d", &N);
        int number;
        for (number = 2; number < N && N % number != 0; ++number);
    if (number == N) { printf("Yes "); }else { printf("No "); } return 0; }

    N = 7
    Yes
    
    
    Process returned 0 (0x0)   execution time : 2.835 s
    Press any key to continue.
     

    2.

    #include <stdio.h>
    int main()
    {
        int N;
        printf("N = ");
        scanf("%d", &N);
    
        int isPrime = 1;
        int number;
        for (number = 2; number < N && isPrime; ++number)//这里的&& isPrime 可以省略
        {
            if (N % number == 0)
        {
            isPrime = 0;
        }
        }
        if (isPrime) {
            printf("Yes
    ");
        } else {
        printf("No
    ");
        }
        return 0;
    }

     11.1 9x9连乘(9X9的正方形)

    #include <stdio.h>
    int main()
    {
        int i,j;
        for (i =2; i <= 9; ++i)
        {
            for (j = 1; j <= 9; ++j)
            {
                printf("%d x %d = %d
    ",i,j, i*j); // printf("*");
            }// printf("
    ");
        }
        return 0;
    }

    11.2 用文字绘制空心长方形的练习

    # include <stdio.h>
    int main()
    {
        int N;
        printf("N = ");
        scanf("%d", &N);
    
        int i,j;
        for (i = 1; i <= N; ++i)
        {
            for (j = 1; j <= N; ++j)
            {
                if (i == 1 || i == N || j == 1 || j == N) // 这一步操作使它空心
                {
                    printf("*");
    
                } else {
                    printf(" ");
                }
            }
            printf("
    ");
    
        }
        return 0;
    }

    N = 7
    *******
    *     *
    *     *
    *     *
    *     *
    *     *
    *******
    
    
    Process returned 0 (0x0)   execution time : 3.764 s
    Press any key to continue.
     

    三角形

    # include <stdio.h>
    int main()
    {
        int N;
        printf("N = ");
        scanf("%d", &N);
    
        int i,j;
        for (i = 1; i <= N; ++i)
        {
            for (j = 1; j <= i; ++j)
            {
                printf("*");
            }
            printf("
    ");
        }
        return 0;
    }

    N = 7
    *
    **
    ***
    ****
    *****
    ******
    *******
    
    
    Process returned 0 (0x0)   execution time : 3.901 s
    Press any key to continue.
     

    11.4 用文字绘制三角形的练习

    # include <stdio.h>
    int main()
    {
        int N;
        printf("N = ");
        scanf("%d", &N);
    
        int i,j;
        for (i = 1; i <= N; ++i)
        {
            for (j = 1; j <= i; ++j)
            {
                printf("*");
            }
            printf("
    ");
        }
        return 0;
    }

    印 1 个星星                                  + 换行
    印 1 个星星 + i个空白 + 1 个星星 + 换行 (i=0)
    印 1 个星星 + i个空白 + 1 个星星 + 换行 (i=1)
    印 1 个星星 + i个空白 + 1 个星星 + 换行 (i=2)
    印 1 个星星 + i个空白 + 1 个星星 + 换行 

    11.5 基于坐标法用文字绘制三角形

    #include <stdio.h>
    int main()
    {
        int N;
        printf("N = ");
        scanf("%d", &N);
    
        int i,j;
        for (i = 1; i <= N; ++i)
        {
            for (j = 1; j <= N; ++j)
            if (i+j >= N+1)
            {
                printf("*");
    
            }else {
                printf(" ");
    
            }
            printf("
    ");
        }
    
        return 0;
    }
          *
         **
        ***
       ****
      *****
     ******
    *******
    // 可以有多种变化,只要看i,j变化

     11.6 找简易方程式整数解(两种方法)

    #include <stdio.h>
    int main()
    {
        int i,j;
        for (i = 1; i <= 30; ++i)
        {
            for (j =1; j <= 30; ++j)
                if (i+j == 30 && i*j == 221)
            {
                printf("%d, %d
    ",i,j);
            }
        }
        return 0;
    }
    
    
    #include <stdio.h>
    int main()
    {
        int i;
        for (i=0;i <= 30/2; ++i)
        {
            int j = 30 - i;
            if (i*j == 221)
            {
                printf("%d, %d
    ", i,j);
            }
    
        }
    
        return 0;
    }
  • 相关阅读:
    Filezilla账号设置多个文件夹
    VS中使用RDLC提示类型不一致
    VS批量添加多个文件
    SQLServer访问WebServices提示:SQL Server 阻止了对组件 'Ole Automation Procedures' 的 过程'sys.sp_OACreate' 的访问
    C#中Newtonsoft.Json 序列化和反序列化 时间格式
    C#注册OCX控件
    js中Tabs插件打开的标签页过多自动关闭
    web项目中使用火狐浏览器导出文件时文件名乱码
    html中table表格标题固定表数据行出现滚动条
    使用js方法将table表格中指定列指定行中相同内容的单元格进行合并操作。
  • 原文地址:https://www.cnblogs.com/pxxfxxxx/p/10731971.html
Copyright © 2011-2022 走看看