Demonstrates nested while statements - C Statement

C examples for Statement:while

Description

Demonstrates nested while statements

Demo Code

#include <stdio.h>

int array[5];/*w  w w.  jav  a  2  s  .  c o m*/

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

    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;
}

Result


Related Tutorials