int main()
{
    int ret = 0;
    int ch = 0;
    char password[20] = {0};
    printf("请输入密码:>");
    scanf("%s",password);
    while((ch = getchar()) != '\n')//清空缓冲区,将缓冲区中的回车标志符读取出
    {
        ;
    }
    printf("请确认(Y/N):>");
    ret = getchar();
    if(ret == 'Y')
    {
        printf("确认成功\n");
    }
    else
    {
        printf("放弃确认\n");
    }
    return 0;
}

for 循环

1.不可在for循环体内修改循环变量;

int main()
{
    int i = 0;
    for(i=0;i<10;i++)
    {
        if(i=5)//陷入死循环
            printf("haha\n");
        printf("hehe\n")
    }
}

2.for循环的控制变量采用“前闭后开”区间写法;

for(i=0;i<10;i++)

3.for循环中变量的初始化和调整均可以省略,但如果判断部分省略,则系统默认恒为真;

do...while()循环

int main()
{
    int i =1;
    do
    {
        printf("%d\n",i);
        i++;
    }
    while(i<=10)
        return 0;
}

1.do...while()至少会被循环一次;

先循环,再做判断

2.计算1!+2!+3!+4!+...n!

int main()
{
    int n = 0;
    int ret =1;
    int sum = 0;
    for(n=1;n<10;n++)
    {
        ret = ret*n;
        sum = sum+ret;
    }
    printf("sum=%d\n",sum);
    return 0;
}