Uses break to exit a loop and quit reading from user - C Statement

C examples for Statement:break

Description

Uses break to exit a loop and quit reading from user

Demo Code

#include <stdio.h>
int main(void)
{
    float length, width;
    /*from www . ja  v  a  2s  .c  o  m*/
    printf("Enter the length of the rectangle:\n");
    while (scanf("%f", &length) == 1)
    {
        printf("Length = %0.2f:\n", length);
        printf("Enter its width:\n");
        if (scanf("%f", &width) != 1)
            break;
        printf("Width = %0.2f:\n", width);
        printf("Area = %0.2f:\n", length * width);
        printf("Enter the length of the rectangle:\n");
    }
    printf("from book2s.co m.\n");
    
    return 0;
}

Result


Related Tutorials