In this tutorial, we will discuss a concept of the C program to print odd or even number in given range using recursion
In this article, we are going to learn how to print odd and even numbers using recursion in the C programming language
When any integer ends in 0,2,4,6,8 and it can be divided by two with the remainder of zero, it is called as an even number.
Example of even numbers – 34,-64,78,788
When any integer ends in 0,1,3,5,7,9 and it cannot be divided without a remainder, it is called as an odd number.
Example for odd numbers – 33,-69,75,785
Here, We can use C programming operators to find odd or even number in the given range
Program 1
This program allows the user to enter two input(number) for the lower limit and upper limit. and it finds whether odd and even numbers in the given range(between upper limit to lower limit)
#include <stdio.h> #include <stdlib.h> void displayEvenOdd(int num, int limit); int main() { int lowerLimit, upperLimit; printf("Enter lower limit\n"); scanf("%d",&lowerLimit); //Received from user number for lower limit printf("Enter upper limit\n"); scanf("%d",&upperLimit); //Received from user number for upper limitr printf("Even/odd numbers from %d to %d are: ",lowerLimit,upperLimit); displayEvenOdd(lowerLimit,upperLimit); getch(); return 0; } void displayEvenOdd(int num, int limit)//recursive function { if(num>limit) return; printf("%d, ",num); displayEvenOdd(num + 2, limit); }
When the above code is executed, it produces the following results
case 1
Enter lower limit 10 Enter upper limit 30 Even/odd numbers from 10 to 30 are: 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30
case 2
Enter lower limit 5 Enter upper limit 25 Even/odd numbers from 5 to 25 are: 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25
Similar post
C program to check whether a number is even or odd
C program to check a number is even or odd using the function
C program to separate Odd and Even numbers from an array
C program to Electricity bill calculation using the function
C program to display all even and odd numbers from 1 to n
C program display odd and even numbers without if statements
C program to calculate the sum of odd and even numbers
Suggested for you
Function in C programming language
Recursion in C programming language
If statements in C programming language
The operator in C programming language
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…