• C语言 while


    C语言 while

    while 语句

    流程图

    案例

    #define _CRT_SECURE_NO_WARNINGS
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <math.h>
    #include <time.h>
    
    int main(void)
    {
        // 格式:while (表达式){}
        // 循环:每次循环将变量i加1直到10停止
        int i = 0;
        while (i < 10)
        {
            printf("%d
    ", i);
            i++;
        }
        return 0;
    }
    while 使用案例
    #define _CRT_SECURE_NO_WARNINGS
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <math.h>
    #include <time.h>
    
    // 敲7程序
    int main(void)
    {
        int i = 1;
        while (i <= 100)
        {
            if (i % 7 == 0 || i % 10 == 7 || i / 10 == 7)
            {
                printf("敲桌子
    ", i);
            }
            else
            {
                printf("%d
    ", i);
            }
            i++;
        }
        return 0;
    }
    while 使用案例:敲七

    do…while 语句

    流程图

    dowhile 与 while 区别

    int i = 0;
    
    // dowhile会先执行语句在判断表达式
        do 
        {
            printf("%d
    ", i);
            i++;
        } while (i < 10);
    
    
    // while会先判断表达式在执行语句
        while (i)
        {
            printf("%d
    ", i);
            i++;
        }

    案例

    #define _CRT_SECURE_NO_WARNINGS
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <math.h>
    #include <time.h>
    
    int main(void)
    {
        int i = 0;
    
        // do{} while (表达式);
        // 限制性语句、在判断表达式
        do 
        {
            printf("%d
    ", i);
            i++;
        } while (i < 10);
    
        return 0;
    }
    while..do 使用案例
  • 相关阅读:
    [团队项目] Scrum 项目 3.0 SCRUM 流程的步骤2: Spring 计划
    《构建之法》第6-7章读后感
    【操作系统】实验二 作业调度模拟程序
    团队项目2.0软件改进分析MathAPP
    团队项目
    结对编程2.0
    电影(网剧))项目
    实验0 了解和熟悉操作系统
    复利计算
    学习进度条
  • 原文地址:https://www.cnblogs.com/xiangsikai/p/12373177.html
Copyright © 2020-2023  润新知