How to use break and continue with while loop in C

1 Answer

0 votes
#include <stdio.h>

int main(void)
{
	int n, sum = 0;

    while (1) 
    {
        printf("Enter a number: ");
        scanf("%d", &n);

        if (n < 0)
            continue;
        else 
            if (n == 0)
                break;
            else
                sum = sum + n;
    }
    printf("The sum is: %d", sum);
    return 0;
}


answered Jul 28, 2014 by avibootz
...