- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Golang Program to Determine Recursively Whether a Given Number is Even or Odd
Steps
- Take a number from the user and store it in a variable.
- Pass the number as an argument to a recursive function.
- Define the base condition as the number to be lesser than 2.
- Otherwise, call the function recursively with the number minus 2.
- Then, return the result and check if the number is even or odd.
- Print the final result.
Enter a number: 124 Number is even! | Enter a number: 567 Number is odd! |
Example
package main import ( "fmt" ) func check(n int) bool{ if n < 2 { return n % 2 == 0 } return check(n - 2) } func main(){ var number int fmt.Print("Enter a number:") fmt.Scanf("%d", &number) check(number) if check(number)==true { fmt.Println("Number is even!") }else{ fmt.Println("Number is odd!") } }
Output
Enter a number:8 Number is even!
- Related Articles
- Python Program to Determine Whether a Given Number is Even or Odd Recursively
- Java program to find whether given number is even or odd
- 8085 program to check whether the given number is even or odd
- Java Program to Check Whether a Number is Even or Odd
- C++ Program to Check Whether Number is Even or Odd
- Check whether given floating point number is even or odd in Python
- How to determine if a number is odd or even in JavaScript?
- Write a Golang program to check whether a given number is prime number or not
- Write a Golang program to check whether a given number is a palindrome or not
- Python program to determine whether the given number is a Harshad Number
- Golang Program to Print the Largest Even and Largest Odd Number in a List
- Golang Program to check the given number is an odd number using library function
- Check whether the length of given linked list is Even or Odd in Python
- PHP program to check if the total number of divisors of a number is even or odd
- Golang Program To Determine If a Given Matrix is a Sparse Matrix

Advertisements