In this tutorial, we will discuss a concept of the C program to check odd or even from the given number using recursion
In this article, we are going to learn how to check odd and even numbers using recursion in the C programming language
Program 1
// C program to check odd or even using recursion #include <stdio.h> //recursive function to check if a number is even int isEven(int num){ if(num==0) return 1; //base case: 0 is even else if (num==1) return 0; //base case: 1 is odd else return isEven(num-2); //recursive case: reduce the number by 2 } int main() { int num; //input a number from the user printf("Enter a number: "); scanf("%d",&num); //check if the number is even or odd using recursion if (isEven(num)) printf("%d is even\n",num); else printf("%d is odd\n",num); return 0; }
When the above code is executed, it produces the following results
Case 1
Enter a number: 53
53 is odd
Case 2
Enter a number: 100
100 is even
Explanation
Similar post
C program to find 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
C program to find whether a number is even or odd
C++ program to find a number is even or odd using the function
C++ program to separate Odd and Even numbers from an array
C++ program to display all even and odd numbers from 1 to n
C++ program calculate Average of odd and even numbers in an array
C++ program to calculate the sum of odd and even numbers
C++ program to find whether a number is even or odd
Java program to find a number is even or odd using the method
Java program to separate Odd and Even numbers from an array
Java program to display all even and odd numbers from 1 to n
Java program display odd and even numbers without if statements
Java program to calculate the sum of odd and even numbers
Java program to find whether a number is even or odd
Suggested for you
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…