Dado el primer término (a), la diferencia común (d) y un número entero N de la serie Progresión aritmética, la tarea es encontrar el término N de la serie.
Ejemplos:
Input : a = 2 d = 1 N = 5 Output : The 5th term of the series is : 6 Input : a = 5 d = 2 N = 10 Output : The 10th term of the series is : 23
Acercarse:
Sabemos que la serie Progresión aritmética es como = 2, 5, 8, 11, 14…. …
En esta serie 2 es el término declarante de la serie.
Diferencia común = 5 – 2 = 3 (Diferencia común en la serie).
entonces podemos escribir la serie como:
t 1 = a 1
t 2 = a 1 + (2-1) * d
t 3 = a 1 + (3-1) * d
.
.
.
t norte = un 1 + (N-1) * re
Para encontrar el término N en la serie Progresión aritmética usamos la fórmula simple.
TN = a1 + (N-1) * d
C++
// CPP Program to find nth term of // Arithmetic progression #include <bits/stdc++.h> using namespace std; int Nth_of_AP(int a, int d, int N) { // using formula to find the // Nth term t(n) = a(1) + (n-1)*d return (a + (N - 1) * d); } // Driver code int main() { // starting number int a = 2; // Common difference int d = 1; // N th term to be find int N = 5; // Display the output cout << "The "<< N <<"th term of the series is : " << Nth_of_AP(a,d,N); return 0; }
Java
// Java program to find nth term // of Arithmetic progression import java.io.*; import java.lang.*; class GFG { public static int Nth_of_AP(int a, int d, int N) { // using formula to find the Nth // term t(n) = a(1) + (n-1)*d return ( a + (N - 1) * d ); } // Driver code public static void main(String[] args) { // starting number int a = 2; // Common difference int d = 1; // N th term to be find int N = 5; // Display the output System.out.print("The "+ N + "th term of the series is : " + Nth_of_AP(a, d, N)); } }
Python3
# Python 3 Program to # find nth term of # Arithmetic progression def Nth_of_AP(a, d, N) : # using formula to find the # Nth term t(n) = a(1) + (n-1)*d return (a + (N - 1) * d) # Driver code a = 2 # starting number d = 1 # Common difference N = 5 # N th term to be find # Display the output print( "The ", N ,"th term of the series is : ", Nth_of_AP(a, d, N)) # This code is contributed # by Nikita Tiwari.
C#
// C# program to find nth term // of Arithmetic progression using System; class GFG { public static int Nth_of_AP(int a, int d, int N) { // using formula to find the Nth // term t(n) = a(1) + (n-1)*d return ( a + (N - 1) * d ); } // Driver code public static void Main() { // starting number int a = 2; // Common difference int d = 1; // N th term to be find int N = 5; // Display the output Console.WriteLine("The "+ N + "th term of the series is : " + Nth_of_AP(a, d, N)); } } // This code is contributed by vt_m.
PHP
<?php // PHP Program to find nth term of // Arithmetic progression function Nth_of_AP($a, $d, $N) { // using formula to find the // Nth term t(n) = a(1) + (n-1)*d return ($a + ($N - 1) * $d); } // Driver code // starting number $a = 2; // Common difference $d = 1; // N th term to be find $N = 5; // Display the output echo("The " . $N . "th term of the series is : " . Nth_of_AP($a, $d, $N)); // This code is contributed by Ajit. ?>
Javascript
<script> // JavaScript Program to find nth term of // Arithmetic progression function Nth_of_AP(a, d, N) { // using formula to find the // Nth term t(n) = a(1) + (n-1)*d return (a + (N - 1) * d); } // Driver code // starting number let a = 2; // Common difference let d = 1; // N th term to be find let N = 5; // Display the output document.write("The "+ N + "th term of the series is : " + Nth_of_AP(a,d,N)); // This code is contributed by Mayank Tyagi </script>
Producción :
The 5th term of the series is : 6
Complejidad de tiempo: O(1), el código se ejecutará en un tiempo constante.
Espacio auxiliar: O(1), no se requiere espacio adicional, por lo que es una constante.
Publicación traducida automáticamente
Artículo escrito por Manish_100 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA