Dado un número n, imprime el n-ésimo número par. El primer número par es 2, el segundo es 4 y así sucesivamente.
Ejemplos:
Input : 3 Output : 6 First three even numbers are 2, 4, 6, .. Input : 5 Output : 10 First five even numbers are 2, 4, 6, 8, 19..
El n-ésimo número par viene dado por la fórmula 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 ?>
Publicación traducida automáticamente
Artículo escrito por rupesh_rao y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA