C Program to Find Total of Even Integers

C Program Continue Statement with Example

The C program below explain how to use of continue statement and ready to execute code with clean output, in easy way with simple steps.

In case, the series contains any negative numbers, the process of evaluation of square root should be bypassed for such numbers because the square root of a negative number is not defined. The continue statement is used to achieve this. The program also prints message saying that the number is negative and keeps an account of negative numbers.

You can also have knowledge on below

The final output includes the number of positive values evaluated and the number of negative items encountered.

Example of Continue Statement

#include <math.h>
main()
{
   int count, negative;
   double number, sqroot;
   printf("Enter 9999 to STOP\n");
   count = 0 ;
   negative = 0 ;
   while (count < = 100)
     {
      printf("Enter a number : ");
      scanf("%lf", &number);
      if (number == 9999)
      break; /* EXIT FROM THE LOOP */
if (number < 0)
 {
    printf("Number is negative\n\n");
    negative++ ;
    continue; /* SKIP REST OF THE LOOP */
}
    sqroot = sqrt(number);
    printf("Number = %lf\n Square root = %lf\n\n",
    number, sqroot);
    count++ ;
}
    printf("Number of items done = %d\n", count);
    printf("\n\nNegative items = %d\n", negative);
    printf("END OF DATA\n");
}

Output display screen below,

Enter 9999 to STOP
Enter a number : 25.0
Number = 25.000000
Square root = 5.000000
Enter a number : 40.5
Number = 40.500000
Square root = 6.363961
Enter a number : -9
Number is negative
Enter a number : 16
Number = 16.000000
Square root = 4.000000
Enter a number : -14.75
Number is negative
Enter a number : 80
Number = 80.000000
Square root = 8.944272
Enter a number : 9999
Number of items done = 4
Negative items = 2
END OF DATA

Let me know if you find any difficulty in understanding this C Program with example and I would be glad to explain it further.