whiles.c

来自「里面包含很多c语言的源码」· C语言 代码 · 共 34 行

C
34
字号
/* Demonstrates nested while statements */

#include <stdio.h>

int array[5];

int main( void )
{
   int ctr = 0,
       nbr = 0;

    printf("This program prompts you to enter 5 numbers\n");
    printf("Each number should be from 1 to 10\n");

    while ( ctr < 5 )
    {
        nbr = 0;
        while (nbr < 1 || nbr > 10)
        {
            printf("\nEnter number %d of 5: ", ctr + 1 );
            scanf("%d", &nbr );
        }

        array[ctr] = nbr;
        ctr++;
    }

    for (ctr = 0; ctr < 5; ctr++)
        printf("Value %d is %d\n", ctr + 1, array[ctr] );

    return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?