Computer Science, asked by rishavkeshav38001, 5 hours ago

Q2. Write a program to take two numbers from the user and print the count of even & odd numbers between the two numbers(both inclusive).

Answers

Answered by Equestriadash
36

The following co‎des have been written using Python.

\tt n1\ =\ int(in put("Enter\ a\ number:\ "))\\n2\ =\ int(in put("Enter\ a\ number:\ "))\\coe\ =\ 0\\coo\ =\ 0\\for\ i\ in\ range(n1,\ n2\ +\ 1):\\{\ \ \ \ \ }if\ i\%2\ ==\ 0:\\{\ \ \ \ \ }{\ \ \ \ \ }coe\ =\ coe\ + 1\\{\ \ \ \ \ }else:\\{\ \ \ \ \ }{\ \ \ \ \ }coo\ =\ coo\ +\ 1\\print("The\ count\ of\ even\ numbers:\ ",\ coe)\\print("The\ count\ of\ odd\ numbers:\ ",\ coo)

Once both numbers have been entered, we assign two variables with the value 0, to represent the count of even/odd numbers. We then start a for loop, an iteration statement used to perform repeated checking. We give the range as (n1, n2 + 1), since both values need to be included as per the question. We check if they're even or odd using a conditional statement. If they're even, the count of the even variable increases by 1 and if they're not even, the count of the odd variable increases by 1. The final output is then printed.

Answered by ItzRainDoll
35

int main()

int count, limit;

printf("Enter start and end value to generate Odd numbers\n");

scanf("%d%d", &count, &limit);

printf("\nOdd numbers between %d and %d are:\n", count, limit);

while(count <= limit)

if(count % 2 != 0)

printf("%d\n", count);

count++;

 return 0;

Hope it helps

Similar questions