UNIVERSIDAD MARIANO GALVEZ
FACULTAD: INGENIERIA
CARRERA: ING EN SISTEMAS Y CIENCIAS DE LA COMPUTACION
CURSO: algoritmos
SECCCION: B
TAREA NO: laboratorio 2
ESTUDIANTE: YALARIK FELIPE OSORIO BARRIOS
CARNE NO: 3190-24-23053
FECHA : 24/07/2024
Ejercicio 1
Códigos Algoritmo Contador
// Definir variable
Definir x Como Entero
// Inicializar x
x <- 1
// Mientras x sea menor o igual a 100, imprimir y aumentar x
Mientras x <= 100 Hacer
Escribir x, "- "
x <- x + 1
Fin Mientras
FinAlgoritmo
package [Link];
public class Contador {
public static void main(String[] args) {
int x = 1;
while (x <= 100) {
[Link](x);
[Link]("- ");
x = x + 1;
}
Ejercicio 2
package [Link];
import [Link];
public class Repetitiva {
public static void main(String[] args) {
Scanner teclado = new Scanner([Link]);
int n, x;
[Link]("Ingrese el valor final: ");
n = [Link]();
x = 1;
while (x <= n) {
[Link](x);
[Link]("- ");
x = x + 1;
[Link](); // Cerrar el scanner al finalizar su uso
Algoritmo Repetitiva
Definir n, x como Entero
Escribir "Ingrese el valor final:"
Leer n
x <- 1
Mientras x <= n Hacer
Escribir x
Escribir "- "
x <- x + 1
Fin Mientras FinAlgoritmo
Ejercicio 3
Proceso ContarPiezasAptas package [Link].estructurarepetitivawhile4;
Definir x, cantidad, n Como Entero
Definir largo Como Real import [Link];
Escribir "Cuantas piezas procesará: " public class EstructuraRepetitivaWhile4 {
Leer n public static void main(String[] args) {
Scanner teclado = new Scanner([Link]);
x <- 1 int x = 1, cantidad = 0, n;
cantidad <- 0 float largo;
Mientras x <= n Hacer [Link]("Cuantas piezas procesará: ");
Escribir "Ingrese la medida de la pieza ", x, ": " n = [Link]();
Leer largo
while (x <= n) {
Si largo >= 1.20 Y largo <= 1.30 Entonces [Link]("Ingrese la medida de la pieza
" + x + ": ");
cantidad <- cantidad + 1
largo = [Link]();
FinSi
if (largo >= 1.20 && largo <= 1.30) {
cantidad++;
x++;
[Link]("La cantidad de piezas aptas
son: " + cantidad);
}
Ejercicio 4
package [Link].estructurarepetitivafor1; Algoritmo EstructuraRepetitivaPara1
Definir f Como Entero
public class EstructuraRepetitivaFor1 { Para f = 1 Hasta 100 Con Paso 1 Hacer
public static void main(String[] ar) { Escribir f, "- "
int f; FinPara
for (f = 1; f <= 100; f++) { FinAlgoritmo
[Link](f);
[Link]("- ");
}
Ejercicio 5
package [Link]. EstructuraRepetitivaFor2;
Algoritmo CalcularSumaYPromedio
Definir suma, f, valor, promedio Como Entero
import [Link];
suma <- 0
public class EstructuraRepetitivaFor2 {
public static void main(String[] ar) {
Para f <- 1 Hasta 10 Con Paso 1 Hacer
Scanner teclado = new Scanner([Link]);
Escribir "Ingrese valor " f ": "
int suma = 0, f, valor, promedio;
Leer valor
suma <- suma + valor
for (f = 1; f <= 10; f++) {
FinPara
[Link]("Ingrese valor " + f + ": ");
valor = [Link]();
promedio <- suma / 10
suma = suma + valor;
}
Escribir "La suma es: " suma
Escribir "El promedio es: " promedio
[Link]("La suma es: " + suma);
FinAlgoritmo
promedio = suma / 10;
[Link]("El promedio es: " +
promedio);
}
Ejercicio 6
package Algoritmo EstructuraRepetitivaDoWhile2
[Link].estructurarepetitivadowhile2; Definir suma, cant, valor, promedio Como Entero
suma <- 0
import [Link]; cant <- 0
Repetir
public class EstructuraRepetitivaDoWhile2 { Escribir "Ingrese un valor (0 para finalizar):"
public static void main(String[] ar) { Leer valor
Scanner teclado = new Scanner([Link]); Si valor <> 0 Entonces
int suma, cant, valor, promedio; suma <- suma + valor
suma = 0; cant <- cant + 1
cant = 0; FinSi
do { Hasta Que valor = 0
[Link]("Ingrese un valor (0 para Si cant <> 0 Entonces
finalizar):");
promedio <- suma / cant
valor = [Link]();
Escribir "El promedio de los valores ingresados
if (valor != 0) { es:", promedio
suma = suma + valor; Sino
cant = cant + 1; Escribir "No se ingresaron valores."
} FinSi
} while (valor != 0); FinAlgoritmo
if (cant != 0) {
promedio = suma / cant;
[Link]("El promedio de los valores
ingresados es:");
[Link](promedio);
} else {
[Link]("No se ingresaron valores.");
}
Ejercicio 7
package Algoritmo EstructuraRepetitivaDoWhile1
[Link].estructurarepetitivadowhile1;
Definir valor Como Entero
import [Link];
Repetir
Escribir "Ingrese un valor entre 0 y 999 (0
public class EstructuraRepetitivaDoWhile1 { finaliza):"
public static void main(String[] ar) { Leer valor
Scanner teclado = new Scanner([Link]); Si valor >= 100 Entonces
int valor; Escribir "Tiene 3 dígitos."
do { Sino
[Link]("Ingrese un valor entre 0 y Si valor >= 10 Entonces
999 (0 finaliza):");
Escribir "Tiene 2 dígitos."
valor = [Link]();
Sino
if (valor >= 100) {
Escribir "Tiene 1 dígito."
[Link]("Tiene 3 dígitos.");
FinSi
} else {
FinSi
if (valor >= 10) {
Hasta Que valor = 0
[Link]("Tiene 2 dígitos.");
FinAlgoritmo
} else {
[Link]("Tiene 1 dígito.");
} while (valor != 0);