Program for n-th even number Last Updated : 20 Aug, 2022 Comments Improve Suggest changes Like Article Like Report Given a number n, print the nth even number. The 1st even number is 2, 2nd is 4 and so on. Examples: Input : 3Output : 6First three even numbers are 2, 4, 6, .. Input : 5Output : 10First five even numbers are 2, 4, 6, 8, 19.. The nth even number is given by the formula 2*n. C++ // CPP program to find the nth even number #include <bits/stdc++.h> using namespace std; // Function to find the nth even number int nthEven(int n) { return (2 * n); } // Driver code int main() { int n = 10; cout << nthEven(n); return 0; } Java // JAVA program to find the nth EVEN number class GFG { // Function to find the nth odd number static int nthEven(int n) { return (2 * n); } // Driver code public static void main(String [] args) { int n = 10; System.out.println(nthEven(n)); } } // This code is contributed // by ihritik Python3 # Python 3 program to find the # nth odd number # Function to find the nth Even number def nthEven(n): return (2 * n) # Driver code if __name__=='__main__': n = 10 print(nthEven(n)) # This code is contributed # by ihritik C# // C# program to find the // nth EVEN number using System; class GFG { // Function to find the // nth odd number static int nthEven(int n) { return (2 * n); } // Driver code public static void Main() { int n = 10; Console.WriteLine(nthEven(n)); } } // This code is contributed // by anuj_67 PHP <?php // PHP program to find the // nth even number // Function to find the // nth even number function nthEven($n) { return (2 * $n); } // Driver code $n = 10; echo nthEven($n); // This code is contributed // by anuj_67 ?> JavaScript // JavaScript program to find the nth even number // Function to find the nth even number function nthEven(n) { return (2 * n); } // Driver code let n = 10; console.log(nthEven(n)); // This code is contributed by phasing17 Output20 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 : DSA series Practice Tags : series Similar Reads Program for n-th odd number 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 2 min read Sum of first n even numbers Given a number n. The problem is to find the sum of first n even numbers.Examples: Input : n = 4 Output : 20 Sum of first 4 even numbers = (2 + 4 + 6 + 8) = 20 Input : n = 20 Output : 420 Naive Approach: Iterate through the first n even numbers and add them. C++ // C++ implementation to find sum of 10 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 Bitwise OR( | ) of all even number from 1 to N Given a number N, the task is to find the bitwise OR( | ) of all even numbers from 1 to N. Examples: Input: 2 Output: 2 Input: 10 Output: 14 Explanation: 2 | 4 | 6 | 8 | 10 = 14 Naive Approach: Initialize the result as 2.Iterate the loop from 4 to n (for all even number) and update result by finding 6 min read Number with even sum of digits Fixed compiling error in java programA positive integer is considered a good number if sum of its digits is even. Find n-th smallest good number. Examples : Input : n = 1 Output : 2 First good number is smallest positive number with sum of digits even which is 2. Input : n = 10 Output : 20 A simple 5 min read Sum of cubes of first n even numbers Given a number n, find the sum of first n even natural numbers. Examples: Input : 2 Output : 72 2^3 + 4^3 = 72Input : 8 Output :10368 2^3 + 4^3 + 6^3 + 8^3 + 10^3 + 12^3 + 14^3 + 16^3 = 10368 A simple solution is to traverse through n even numbers and find the sum of cubes. C++ // Simple C++ method 5 min read Like