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
The following codes have been written using Python.
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.
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