Está en la página 1de 41

UNIVERSIDAD NACIONAL DEL CALLAO

FACULTAD DE INGENIERÍA ELÉCTRICA Y ELECTRÓNICA


ESCUELA PROFESIONAL DE INGENIERÍA ELECTRÓNICA

PROGRAMACIÓN AVANZADA
LABORATORIO SESIÓN 07
Estructuras cíclicas-repetitivas-bucles
ESTUDIANTE:
Bullon Espiritu Andrea Alejandra
CÓDIGO:
1823221121
DOCENTE:
Dr. Fernando Mendoza Apaza

2021
PROBLEMAS DIRIGIDOS
PROBLEMA 1:
Construir un Programa que imprima los N primeros, su sumatoria y su promedio.
CÓDIGO EN PSEINT:
Algoritmo sumatoria_promedio
Definir n, sumatoria, i Como Entero
Definir promedio Como Real

Escribir "Ingrese la cantidad de numeros que desea:"


Leer n;
sumatoria=0
promedio=0
Para i=1 Hasta n Con Paso 1 Hacer
Escribir sin saltar i, " "
sumatoria=sumatoria + i
promedio= sumatoria/n
Fin Para

Escribir " "

Escribir "La suma de los ",n," primeros numeros es :",sumatoria;


Escribir "El promedio es: " promedio;
FinAlgoritmo
DIAGRAMA DE FLUJO:
DIAGRAMA N/S:
EJECUCIÓN O PRUEBA DE CONSOLA:
- PSEINT:
- JAVA:
CÓDIGO EN JAVA:
package sumatoria_promedio;
import java.util.Scanner;
import java.io.*;
public class Sumatoria_promedio {

public static void main(String[] args) throws IOException {


BufferedReader Buffer = new BufferedReader(new
InputStreamReader(System.in));
Scanner leer =new Scanner(System.in);

int i,n,sumatoria;
double promedio;

System.out.println("Ingrese la cantidad de numeros que desea:");


n = Integer.parseInt(Buffer.readLine());
sumatoria = 0;
promedio = 0;
for (i=1;i<=n;i++) {
System.out.println(i+" ");
sumatoria = sumatoria+i;
promedio = sumatoria/n;
}
System.out.println(" ");
System.out.println("La suma de los "+n+" primeros numeros es
:"+sumatoria);
System.out.println("El promedio es: "+promedio);
}
}
PROBLEMA 2:
Construir un Programa que calcule los n primeros términos de la serie representada por:

CÓDIGO EN PSEINT:
Algoritmo taylor_modificada
Definir suma,serie,x,factorial Como Real;
Escribir "Cuantos terminos desea en la serie";
leer n
Escribir "Digite el valor de x";
Leer x
suma=1;
factorial=1
para i=1 hasta n Con Paso 1 hacer
factorial=factorial*i;
serie=((-1)^i)*(x^i)/(factorial);
suma=suma+serie;
FinPara

Escribir "f(x)=",suma;
FinAlgoritmo
DIAGRAMA DE FLUJO:
DIAGRAMA N/S:
EJECUCIÓN O PRUEBA DE CONSOLA:
- PSEINT:

- JAVA:

CÓDIGO EN JAVA:
package taylor_modificada;
import java.util.Scanner;
import java.io.*;
public class Taylor_modificada {

public static void main(String[] args) throws IOException {


BufferedReader Buffer = new BufferedReader(new
InputStreamReader(System.in));
Scanner leer =new Scanner(System.in);
double factorial,i,n,serie,suma,x;
System.out.println("Cuantos terminos desea en la serie");
n = Double.parseDouble(Buffer.readLine());
System.out.println("Digite el valor de x");
x = Double.parseDouble(Buffer.readLine());
suma = 1;
factorial = 1;
for (i=1;i<=n;i++) {
factorial = factorial*i;
serie = (Math.pow((-1),i))*(Math.pow(x,i))/(factorial);
suma = suma+serie;
}
System.out.println("f(x)="+suma);
}

}
PROBLEMA 3:
Construir un Programa que imprima los N primeros números de la serie Fibonacci y su
sumatoria, la cual está representada por:
0, 1, 1, 2, 3, 5, 8, 13, 21, …
CÓDIGO EN PSEINT:
Algoritmo serie_fibonacci
Definir n Como Entero
Definir suma,serie,a,b,c Como Real
suma=1
Escribir "Digite cuantos terminos quiere (minimo 3)";
Leer n
Mientras n<3 Hacer
Escribir "Error digite un numero mayor igual a 3";
Leer n
FinMientras
Escribir Sin Saltar "0,1";
a=0;
b=1;
para i=2 hasta n Con Paso 1 Hacer
c=a+b;
Escribir Sin Saltar ",",c;
a=b;
b=C;
suma=suma+c
FinPara
Escribir "";
Escribir "La suma de es: ",suma;
FinAlgoritmo
DIAGRAMA DE FLUJO:
DIAGRAMA N/S:
EJECUCIÓN O PRUEBA DE CONSOLA:
- PSEINT:

- JAVA:

CÓDIGO EN JAVA:
package serie_fibonacci;
import java.util.Scanner;
import java.io.*;
public class Serie_fibonacci {

public static void main(String[] args) throws IOException {


BufferedReader Buffer = new BufferedReader(new
InputStreamReader(System.in));
Scanner leer =new Scanner(System.in);

double a,b,c,i,serie,suma;
int n;

suma = 1;
System.out.println("Digite cuantos terminos quiere (minimo 3)");
n = Integer.parseInt(Buffer.readLine());
while (n<3) {
System.out.println("Error digite un numero mayor igual a 3");
n = Integer.parseInt(Buffer.readLine());
}
System.out.print("0 1");
a = 0;
b = 1;
for (i=2;i<=n;i++) {
c = a+b;
System.out.print(" "+c);
a = b;
b = c;
suma = suma+c;
}
System.out.println("");
System.out.println("La suma de es: "+suma);
}
}
PROBLEMA 4:
Construir un Programa que imprima los N primeros números de la siguiente serie y su
sumatoria, la cual está representada por:
0, 1, 2, 3, 6, 11, 20, 37, 68, …
CÓDIGO EN PSEINT:
Algoritmo fibonacci_modificada
Definir n Como Entero
Definir suma,serie,a,b,c,d Como Real
suma=3;
Escribir "Cuantos terminos desea (minimo 4):";
Leer n
Mientras n<4 Hacer
Escribir "Error digite un numero mayor igual a 3";
Leer n
FinMientras
Escribir Sin Saltar "0,1,2";
a=0;
b=1;
c=2;
para i=4 hasta n Con Paso 1 Hacer
d=a+b+c;
Escribir Sin Saltar ",",d;
a=b;
b=C;
c=d;
suma=suma+d;
FinPara
Escribir "";
Escribir "La sumatoria es: ",suma;
FinAlgoritmo
DIAGRAMA DE FLUJO:
DIAGRAMA N/S:
EJECUCIÓN O PRUEBA DE CONSOLA:
- PSEINT:

- JAVA:

CÓDIGO EN JAVA:
package fibonacci_modificada;
import java.util.Scanner;
import java.io.*;
public class Fibonacci_modificada {

public static void main(String[] args) throws IOException {


BufferedReader Buffer = new BufferedReader(new
InputStreamReader(System.in));
Scanner leer =new Scanner(System.in);

double a,b,c,d,i,serie,suma;
int n;

suma = 3;
System.out.println("Cuantos terminos desea (minimo 4):");
n = Integer.parseInt(Buffer.readLine());
while (n<4) {
System.out.println("Error digite un numero mayor igual a 3");
n = Integer.parseInt(Buffer.readLine());
}
System.out.print("0 1 2");
a = 0;
b = 1;
c = 2;
for (i=4;i<=n;i++) {
d = a+b+c;
System.out.print(" "+d);
a = b;
b = c;
c = d;
suma = suma+d;
}
System.out.println("");
System.out.println("La sumatoria es: "+suma);
}
}
PROBLEMA 5:
El número natural e se puede calcular con esta serie matemática:

Entre mayor sea el número n, mayor será la precisión del número natural e. Hacer un
programa que calcule el número natural e, dado el número de términos requeridos por
el usuario.
CÓDIGO EN PSEINT:
Algoritmo calcular_e
Definir n,factorial,suma,serie como real;
Escribir "Cuantos terminos de precisión desea";
Leer n;
factorial=1
suma=0;
Para i=0 hasta n-1 Con Paso 1
si i=0 Entonces
factorial=1
serie=1/factorial;
suma=suma+serie;
SiNo
factorial=factorial*i
serie=1/factorial;
suma=suma+serie;
FinSi
FinPara
Escribir "e=",suma;
FinAlgoritmo
DIAGRAMA DE FLUJO:
DIAGRAMA N/S:
EJECUCIÓN O PRUEBA DE CONSOLA:
- PSEINT:

- JAVA:

CÓDIGO EN JAVA:
package cacular_e;
import java.util.Scanner;
import java.io.*;
public class Cacular_e {

public static void main(String[] args) throws IOException {


BufferedReader Buffer = new BufferedReader(new
InputStreamReader(System.in));
Scanner leer =new Scanner(System.in);

double factorial,i,n,serie,suma;

System.out.println("Cuantos terminos de precisión desea");


n = Double.parseDouble(Buffer.readLine());
factorial = 1;
suma = 0;
for (i=0;i<=n-1;i++) {
if (i==0) {
factorial = 1;
serie = 1/factorial;
suma = suma+serie;
} else {
factorial = factorial*i;
serie = 1/factorial;
suma = suma+serie;
}
}
System.out.println("e = "+suma);
}
}
PROBLEMA 6:
El número 𝜋 (pi) se puede calcular con esta serie matemática:

Entre mayor sea el número n, mayor será la precisión del número 𝜋. Hacer un programa
que calcule el número 𝜋, dado el número de términos requeridos por el usuario.
CÓDIGO EN PSEINT:
Algoritmo calculo_pi
Definir n,suma,serie como real
Escribir "Cuantos terminos de precision desea: "
Leer n;
Para i=0 hasta n-1 Con Paso 1 hacer
serie=1/(2*i+1);
signo=(-1)^(i)
suma=suma+(serie*signo)
FinPara
Escribir "pi=",suma*4;
FinAlgoritmo
DIAGRAMA DE FLUJO:
DIAGRAMA N/S:
EJECUCIÓN O PRUEBA DE CONSOLA:
- PSEINT:

- JAVA:

CÓDIGO EN JAVA:
package calculo_pi;

import java.util.Scanner;

import java.io.*;

public class Calculo_pi {

public static void main(String[] args) throws IOException {

BufferedReader Buffer = new BufferedReader(new InputStreamReader(System.in));

Scanner leer =new Scanner(System.in);

double i,n,serie,signo,suma=0;

System.out.println("Cuantos terminos de precision desea: ");

n = Double.parseDouble(Buffer.readLine());

for (i=0;i<=n-1;i++) {

serie = 1/(2*i+1);

signo = Math.pow((-1),(i));

suma = suma+(serie*signo);

System.out.println("pi = "+suma*4);

}
}

También podría gustarte