computer






 

Question by  marvy (1)

How can I get the population of even and odd integers in a given range using C++ program?

 
+6

Answer by  James1290 (86)

In order to do this you must create a for loop cycling through all your numbers. Then within the loop, increment a counter of evens if (num % 2 == 0) and odds otherwise. If you only need numbers within a range, create an if statement first to check if the number is in range before counting.

 
+5

Answer by  Amber40 (24961)

Find the total amount of number by subtracting the highest from the lowest and add 1. To see if the first one is even/odd by dividing it by 2 and checking the remainder. Then divide the total amount of number and whichever the first is the larger half will be.

 
You have 50 words left!