zoukankan      html  css  js  c++  java
  • 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 使用案例
  • 相关阅读:
    05391
    05390
    05389
    05388
    1006 Sign In and Sign Out (25分)
    1002 A+B for Polynomials (25分)
    1005 Spell It Right (20分)
    1003 Emergency (25分)
    1001 A+B Format (20分)
    HDU 2962 Trucking
  • 原文地址:https://www.cnblogs.com/xiangsikai/p/12373177.html
Copyright © 2011-2022 走看看