Program for n-th odd number Last Updated : 20 Aug, 2022 Comments Improve Suggest changes Like Article Like Report Given a number n, print the nth odd number. The 1st odd number is 1, 2nd is 3, and so on.Examples: Input : 3 Output : 5 First three odd numbers are 1, 3, 5, .. Input : 5 Output : 9 First 5 odd numbers are 1, 3, 5, 7, 9, .. The nth odd number is given by the formula 2*n-1. C++ // CPP program to find the nth odd number #include <bits/stdc++.h> using namespace std; // Function to find the nth odd number int nthOdd(int n) { return (2 * n - 1); } // Driver code int main() { int n = 10; cout << nthOdd(n); return 0; } Java // JAVA program to find the nth odd number class GFG { // Function to find the nth odd number static int nthOdd(int n) { return (2 * n - 1); } // Driver code public static void main(String [] args) { int n = 10; System.out.println(nthOdd(n)); } } // This code is contributed // by ihritik Python3 # Python 3 program to find the # nth odd number # Function to find the nth odd number def nthOdd(n): return (2 * n - 1) # Driver code if __name__=='__main__': n = 10 print(nthOdd(n)) # This code is contributed # by ihritik C# // C# program to find the nth odd number using System; class GFG { // Function to find the nth odd number static int nthOdd(int n) { return (2 * n - 1); } // Driver code public static void Main() { int n = 10; Console.WriteLine(nthOdd(n)); } } // This code is contributed // by inder_verma PHP <?php // PHP program to find the // Nth odd number // Function to find the // Nth odd number function nthOdd($n) { return (2 * $n - 1); } // Driver code $n = 10; echo nthOdd($n); // This code is contributed // by inder_verma ?> JavaScript <script> // Javascript program to find the nth odd number // Function to find the nth odd number function nthOdd(n) { return (2 * n - 1); } // Driver code var n = 10; document.write( nthOdd(n)); </script> Output: 19 Time Complexity: O(1) Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Program for n-th odd number R rupesh_rao Follow Improve Article Tags : Misc Mathematical Computer Science Fundamentals DSA series +1 More Practice Tags : MathematicalMiscseries Similar Reads Program to find Nth odd Fibonacci Number Given an integer N. The task is to find the Nth odd Fibonacci number.The odd number fibonacci series is as: 1, 1, 3, 5, 13, 21, 55, 89, 233, 377, 987, 1597.............and so on.Note: In the above series we have omitted even terms from the general fibonacci sequence. Examples: Input: N = 3 Output: 3 3 min read Program to print Even Odd Number Pyramid Given the total number of rows as n, the task is to print the given pattern. * 1* *2* 1*3* *2*4* 1*3*5* *2*4*6* 1*3*5*7* *2*4*6*8* 1*3*5*7*9* . . Examples: Input: n = 5 Output: * 1* *2* 1*3* *2*4* Input: n = 10 Output: * 1* *2* 1*3* *2*4* 1*3*5* *2*4*6* 1*3*5*7* *2*4*6*8* 1*3*5*7*9* Below is the sol 4 min read C++ program to print all Even and Odd numbers from 1 to N Given a number N, the task is to print N even numbers and N odd numbers from 1. Examples: Input: N = 5 Output: Even: 2 4 6 8 10 Odd: 1 3 5 7 9 Input: N = 3 Output: Even: 2 4 6 Odd: 1 3 5 Approach: For Even numbers:Even numbers are numbers that are divisible by 2.To print even numbers from 1 to N, tr 4 min read Find sum of odd factors of a number Given a number n, the task is to find the odd factor sum.Examples : Input : n = 30Output : 24Odd dividers sum 1 + 3 + 5 + 15 = 24 Input : 18Output : 13Odd dividers sum 1 + 3 + 9 = 13 Approach :- Naive approach in o(n) time complexity The first approach involves iterating over all factors of the give 10 min read Smallest odd number with N digits Given a number N. The task is to find the smallest N digit ODD number.Examples: Input: N = 1 Output: 1 Input: N = 3 Output: 101 Approach: There can be two cases depending on the value of N. Case 1 : If N = 1 then answer will be 1. Case 2 : If N != 1 then answer will be (10^(n-1)) + 1 because the ser 3 min read Like