100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Programa resuelto con recursividad $3.49   Add to cart

Class notes

Programa resuelto con recursividad

 2 views  0 purchase
  • Course
  • Institution

Programa que plantea la resolución de un problema con recursividad. Muestra el código y la explicación paso a paso del mismo

Preview 1 out of 2  pages

  • February 1, 2024
  • 2
  • 2023/2024
  • Class notes
  • Angélica enciso
  • All classes
avatar-seller
Problema:

13. Dada la siguiente serie an=an-1+2n, para n > 0 (para n=0, an=0), diseñar una función recursiva que
calcule el término n de la serie.

Solución:

Crear un programa recursivo que nos pida el término “n” a buscar, el cual es el siguiente:

public class Calcular_n {

public static void main(String[] args) {
// Alrak Studios (2023)
int n;
Scanner scanner = new Scanner(System.in);
System.out.println("Ingrese el término a buscar:");
n = scanner.nextInt();
int r=CS(n);
System.out.println("El termino " + n + " de la serie es: " + r);
}
public static int CS(int n) {
if (n==0) {
return 0;
}else {
int an= CS(n-1);
return (an-1)+2*n;
} //Formula: an = an-1 + 2n
}


Interpretación del programa:

Lo que hace el programa es pedir al usuario el término “n” a buscar. En nuestro caso base tenemos:

if (n==0) {return 0;}

Lo cual significa que si “n” o “an” es igual a 0, entonces nuestro programa terminará.

En caso de nuestra parte recursiva tenemos:

else {
int an= CS(n-1);
return (an-1)+2*n;
}

El cuál crea la variable “an” para guardar la posición en la que se encuentra y sucesivamente realizar la
operación de la fórmula an-1+2n.

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller 02benitezriveraalexa. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $3.49. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

67474 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$3.49
  • (0)
  Add to cart