I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.
#include <stdio.h>
// Function declaration
void printevenodd(int cur, int limit);
int main()
{
int lowerLimit, upperLimit;
// Inputting lower and upper limit from user
printf("Enter lower limit: ");
scanf("%d", &lowerLimit);
printf("Enter upper limit: ");
scanf("%d", &upperLimit);
printf("Even/odd Numbers from %d to %d are: ", lowerLimit, upperLimit);
printevenodd(lowerLimit, upperLimit);
return 0;
}
//Recursive function to print even or odd numbers in a given range.
void printevenodd(int cur, int limit)
{
if(cur > limit)
return;
printf("%d, ", cur);
// Recursively call to printevenodd to get next value
printevenodd(cur + 2, limit);
}
I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.
Result:
Enter lower limit: 10
Enter upper limit: 40
Even/odd Numbers from 10 to 40 are: 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40,
need an explanation for this answer? contact us directly to get an explanation for this answer