Count the number of even numbers between 0 and 100. - C Data Type

C examples for Data Type:int

Description

Count the number of even numbers between 0 and 100.

Demo Code

#include <stdio.h>

int main( void )
{
   static int count = 0;

   for (int x = 0; x < 101; x++)
   {//from   w  w w  .j  a  v  a 2  s .c o m
      if (x % 2 == 0)  /*if x is even...*/
      count++;  /*add 1 to count.*/

   }

   printf("There are %d even numbers.\n", count);
   return 0;
}

Result


Related Tutorials