Check if an Octal number is Even or Odd Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Given an Octal number N, check whether it is even or odd.Examples: Input: N = 7234 Output: Even Input: N = 333333333 Output: Odd Naive Approach: Convert the number from Octal base to Decimal base.Then check if the number is even or odd, which can be easily checked by dividing by 2. Time Complexity: O(N)Efficient approach: Since Octal numbers contain digits from 0 to 7, therefore we can simply check if the last digit is either '0', '2', '4' or '6' . If it is, then the given Octal number will be Even, else Odd.Below is the implementation of the above approach. C++ // C++ code to check if a Octal // number is Even or Odd #include <bits/stdc++.h> using namespace std; // Check if the number is odd or even string even_or_odd(string N) { int len = N.size(); // Check if the last digit // is either '0', '2', '4', // or '6' if (N[len - 1] == '0' || N[len - 1] == '2' || N[len - 1] == '4' || N[len - 1] == '6') return ("Even"); else return ("Odd"); } // Driver code int main() { string N = "735"; cout << even_or_odd(N); return 0; } Java // Java code to check if a Octal // number is Even or Odd import java.io.*; class GFG{ // Check if the number is odd or even static String even_or_odd(String N) { int len = N.length(); // Check if the last digit // is either '0', '2', '4', // or '6' if (N.charAt(len - 1) == '0' || N.charAt(len - 1) == '2' || N.charAt(len - 1) == '4' || N.charAt(len - 1) == '6') return ("Even"); else return ("Odd"); } // Driver code public static void main(String[] args) { String N = "735"; System.out.print(even_or_odd(N)); } } // This code is contributed by Rajput-Ji Python 3 # Python 3 code to check if a Octal # number is Even or Odd # Check if the number is odd or even def even_or_odd( N): l = len(N); # Check if the last digit # is either '0', '2', '4', # or '6' if (N[l - 1] == '0'or N[l - 1] == '2'or N[l - 1] == '4' or N[l - 1] == '6'): return ("Even") else: return ("Odd") # Driver code N = "735" print(even_or_odd(N)) # This code is contributed by ANKITKUMAR34 C# // C# code to check if a Octal // number is Even or Odd using System; public class GFG{ // Check if the number is odd or even static String even_or_odd(String N) { int len = N.Length; // Check if the last digit // is either '0', '2', '4', // or '6' if (N[len - 1] == '0' || N[len - 1] == '2' || N[len - 1] == '4' || N[len - 1] == '6') return ("Even"); else return ("Odd"); } // Driver code public static void Main(String[] args) { String N = "735"; Console.Write(even_or_odd(N)); } } // This code contributed by Princi Singh JavaScript <script> // Javascript code to check if a Octal // number is Even or Odd // Check if the number is odd or even function even_or_odd(N) { var len = N.length; // Check if the last digit // is either '0', '2', '4', // or '6' if (N[len - 1] == '0' || N[len - 1] == '2' || N[len - 1] == '4' || N[len - 1] == '6') return ("Even"); else return ("Odd"); } // Driver code var N = "735"; document.write(even_or_odd(N)); // This code is contributed by Mayank Tyagi </script> Output: Odd Time Complexity: O(1) Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Check if a HexaDecimal number is Even or Odd A apurvaraj Follow Improve Article Tags : DSA number-digits number-theory Practice Tags : number-theory Similar Reads Check if a N base number is Even or Odd Given a number num in base N, check whether it is even or odd.Examples: Input: num = 10, N = 8 Output: Even Explanation: 108 = 810, which is even Input: num = 122, N = 5 Output: Odd Explanation: 1225 = 3710, which is odd Approach: Convert the number num from Base N to Decimal base.Check whether the 6 min read Check if a N base number is Even or Odd Given a number num in base N, check whether it is even or odd.Examples: Input: num = 10, N = 8 Output: Even Explanation: 108 = 810, which is even Input: num = 122, N = 5 Output: Odd Explanation: 1225 = 3710, which is odd Approach: Convert the number num from Base N to Decimal base.Check whether the 6 min read Check if a N base number is Even or Odd Given a number num in base N, check whether it is even or odd.Examples: Input: num = 10, N = 8 Output: Even Explanation: 108 = 810, which is even Input: num = 122, N = 5 Output: Odd Explanation: 1225 = 3710, which is odd Approach: Convert the number num from Base N to Decimal base.Check whether the 6 min read Check if a HexaDecimal number is Even or Odd Given a HexaDecimal number, check whether it is even or odd.Examples: Input: N = ABC7787CC87AA Output: Even Input: N = 9322DEFCD Output: Odd Naive Approach: Convert the number from Hexadecimal base to Decimal base.Then check if the number is even or odd, which can be easily checked by dividing by 2. 4 min read Check if a HexaDecimal number is Even or Odd Given a HexaDecimal number, check whether it is even or odd.Examples: Input: N = ABC7787CC87AA Output: Even Input: N = 9322DEFCD Output: Odd Naive Approach: Convert the number from Hexadecimal base to Decimal base.Then check if the number is even or odd, which can be easily checked by dividing by 2. 4 min read Check if a HexaDecimal number is Even or Odd Given a HexaDecimal number, check whether it is even or odd.Examples: Input: N = ABC7787CC87AA Output: Even Input: N = 9322DEFCD Output: Odd Naive Approach: Convert the number from Hexadecimal base to Decimal base.Then check if the number is even or odd, which can be easily checked by dividing by 2. 4 min read Like