欢迎光临!

3.2while循环

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

//从1加到100
int main()
{
    int i = 1;
    int    total = 0; //存贮最终的和
    while (i<=100) //这里不能写分号
    {
        total = total + i;
        i++;
    }
    printf("total=%d\n", total);
    system("pause");
    return 0;

}https://github.com/mzdbxwg/xiao/edit/main/3.2while%E5%BE%AA%E7%8E%AF.c

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

//从1加到100
int main()
{
    int i = 1;
    int    total = 0; //存贮最终的和
    while (i<=100) //这里不能写分号
    {
        total = total + i;
        i++;
    }
    printf("total=%d\n", total);
    system("pause");
    return 0;

}

 

posted @ 2022-08-13 10:43  国师编程  阅读(20)  评论(0)    收藏  举报
欢迎光临!!