Sie sind auf Seite 1von 10

3.

1 Dos tringulos son congruentes si tienen la misma forma y tamao, es decir,


sus ngulos y lados correspondientes son iguales. Elaborar un programa que leas
los tres ngulos y lados de dos tringulos e imprima si son congruentes. (if)
Anlisis
Entrada:
Tringulos (angulos y lados)
Proceso: comparar los angulos y los lados de los tringulos
Salida: son congruentes si tienen la misma forma y tamao

Pseudocdigo
Congruentes
Inicio
1 escribir (angulo 1)
2 leer a1
3 escribir (angulo 2)
4 leer a2
5 escribir (angulo 3)
6 leer a3
7 escribir (lado 1)
8 leer l1
9 escribir (lado 2)
10 leer l2
11 escribir (lado 3)
12 leer l3
13 si (a1=a2)
14 escribir (Triangulos congruentes)

15 si (a1T1=a1T2)
Y (a2T1=a2T2)
Y (a3T1=a3T2)
Y (l1T1=l1T2)
Y (l2T1=l2T2)
Y (l3T1=l3T2)
16 escribir (tringulos congruentes)
17 fin

Cdigo en java
package congruentes_1;
import javax.swing.*;
public class Congruentes
{
public static void main(String []args)
{
boolean congruente=false;
//Triangulo 1
//lados
int t1_lado1=Integer.parseInt(JOptionPane.showInputDialog("Ingresa el lado
[1] del triangulo [1]"));
int t1_lado2=Integer.parseInt(JOptionPane.showInputDialog("Ingresa el lado
[2] del triangulo [1]"));
int t1_lado3=Integer.parseInt(JOptionPane.showInputDialog("Ingresa el lado
[3] del triangulo [1]"));
//Angulos
int t1_ang1=Integer.parseInt(JOptionPane.showInputDialog("Ingresa el
angulo [1] del triangulo [1]"));
int t1_ang2=Integer.parseInt(JOptionPane.showInputDialog("Ingresa el
angulo [2] del triangulo [1]"));
int t1_ang3=Integer.parseInt(JOptionPane.showInputDialog("Ingresa el
angulo [3] del triangulo [1]"));
//Triangulo 2
//lados

int t2_lado1=Integer.parseInt(JOptionPane.showInputDialog("Ingresa el lado


[1] del triangulo [2]"));
int t2_lado2=Integer.parseInt(JOptionPane.showInputDialog("Ingresa el lado
[2] del triangulo [2]"));
int t2_lado3=Integer.parseInt(JOptionPane.showInputDialog("Ingresa el lado
[3] del triangulo [2]"));
//Angulos
int t2_ang1=Integer.parseInt(JOptionPane.showInputDialog("Ingresa el
angulo [1] del triangulo [2]"));
int t2_ang2=Integer.parseInt(JOptionPane.showInputDialog("Ingresa el
angulo [2] del triangulo [2]"));
int t2_ang3=Integer.parseInt(JOptionPane.showInputDialog("Ingresa el
angulo [3] del triangulo [2]"));
//Proceso
//Comparar angulos de triangulos
if(t1_ang1 == t2_ang1)
{
if(t1_ang2 == t2_ang2)
{
if(t1_ang3 == t2_ang3)
{
congruente=true;
}
else
{
congruente=false;
}
}
else
{
congruente=false;
}
}
else
{
congruente=false;
}
if(t1_lado1 == t2_lado1)
{
if(t1_lado2 == t2_lado2)
{
if(t1_lado3 == t2_lado3)
{
congruente=true;

}
else
{
congruente=false;
}
}
else
{
congruente=false;
}
}
else
{
congruente=false;
}
//Salida
if(congruente==true)
{
JOptionPane.showMessageDialog(null,"Los triangulos son congruentes");
}
else
{
JOptionPane.showMessageDialog(null,"Los triangulos NO son
congruentes");
}
}
}

3.2 Elaborar un programa que lea N nmeros diferentes y calcule e imprima


el mayor. (for)
Anlisis
Entrada: se ingresan 5 Num (80, -1, 100, 35, 1000)
Proceso: Se compara cada numero i=0 i=1 i=2 i=3 i=4
Para (i desde 0; mientras que i sea menor a 5; aumentar i a +1)
Como se determina el mayor
Mayor=0

Leer (numero)
Si (numero> mayor)
Mayor =numero
Salida: Mayor=numero
Pseudocdigo
Mayor
Inicio
1 variables: n mayor tipo
2 escribir (se ingresa nmeros N)
3 leer (N)
4 desde i=0 hasta N
5 leer (Numero)
6 si Numero>Mayor
Mayor

Numero

7 fin si
8 fin desde
9 fin mayor

Cdigo en java
package mayor;
import java.util.Scanner;
public class Mayor {
public static void main(String[] args) {
int N, i, Mayor=0, Numero;
Scanner nuevo=new Scanner(System.in);
System.out.println("cuantos numeros'");
N=nuevo.nextInt();
for(i=0; i<N; i++){
System.out.println("ingrese un numero");

Numero=nuevo.nextInt();
if(Numero>Mayor){
Mayor=Numero;
System.out.println(+Mayor);
}
}
System.out.println("el mayor es"+Mayor);
}
}

3.3 Elaborar un programa para enlistar los nmeros pares entre 0 y 20.
(while)
Anlisis
Entrada: se ingresa los numero del 0 al 20
Proceso: se comparam los nmeros que son pares
Salida: imprimir los nmeros pares entre el 0 y el 20
Pseudocdigo
Pares
Inicio
1 variables nmeros pares
2 escribir los nmeros pares entre o y 20
3 leer n <=0
4 escribir numero
Num<=num+2
5 fin

Cdigo en java
package numerospares;

public class Numerospares {


public static void main(String[] args) {
int num=1;
while (num<=20){
if(num%2==0){
System.out.println(num);
}
num++;
}
}

3.4 Elaborar un programa que mida la inflacin sifrida por ciertos artculos y que
imprima
el
siguiente
reporte:
(do-while)
ANALISIS DE INFLACIN
ARTICULO
PRECIO
ANTERIOR ACTUAL INFLACIN

PRECIO

XXXXXXXX
99,999.99
.
.
XXXXXXXX 99,999.99 99,999.99 99.99
Promedio
de
Artculo
con
mayor
Procentaje mayor de inflacin: 99.99
Datos

PORCENTAJE

99,999.99

99.99

inflacin:
99.99
inflacin:
xxxxxxxxxxxxxxxxxxxxxxxxx

disponibles

de

cada

artculo:

Descripcin
Precio
Precio
Forma

anterior
actual
de

calcular

el

porcentaje

de

PTJE. INFLACION=(Precioactual - Precio anterior/Precioanterior) x 100

inflacin:

Anlisis
Entrada
Datos
articulo : Cadena
precioAnt: Real
precioAct: Real
ptjeInfla: Real
Proceso: Mtodo establecerArticulo(nom: Cadena)
a. articulo = nom
b. Fin Mtodo establecerArticulo
3. Mtodo establecerPrecioAnt(pAnt: Real)
a. precioAnt = pAnt
b. Fin Mtodo establecerPrecioAnt
4. Mtodo establecerPrecioAct(pAct: Real)
a. precioAct = pAct
b. Fin Mtodo establecerPrecioAct
5. Mtodo calcularPtjeInfla()
a. ptjeInfla = ((precioAct-precioAnt)/precioAnt)*100 b.
Fin Mtodo calcularPtjeInfla
6. Mtodo obtenerArticulo() Cadena
a. return articulo
b. Fin Mtodo obtenerArticulo
7. Mtodo obtenerPrecioAnt() Real
a. return precioAnt
b. Fin Mtodo obtenerPrecioAnt

8. Mtodo obtenerPrecioAct() Real


a. return precioAct
b. Fin Mtodo obtenerPrecioAct
9. imprimir el Mtodo obtenerPtjeInfla() Real
a. return ptjeInfla
b. Fin Mtodo obtenerPtjeInfla

Pseudocodigo
inflacion
Inicio
Mtodo principal()
a. Declarar Variables
art, artMayor: Cadena
totArticulos: Entero
preAn, preAc, totInfla,
mayorInfla, promInfla: Real
otro: Carcter
b. Imprimir encabezado
c. totArticulos = 0
totInfla = 0
mayorInfla = 0
Declarar, crear e iniciar objeto
Solicitar Articulo, precio actual y precio anterior
Leer art, preAc, preAn
Calcular objArti.calcularPtjeInfla()

Imprimir objArti.obtenerArticulo()
Preguntar Desea procesar otro artculo(S/N)?
Fin Mtodo principal
Fin

Cdigo en java
package inflacion;
import java.util.Scanner;
public class inflacion {
public static void main(String[] args) {
double precact=0, precant=0, porcentaje=0;
Scanner nuevo=new Scanner(System.in);
System.out.println("Ingrese nombre del articulo");
String artic=nuevo.nextLine();//().charAt(0);
System.out.println("Ingrese el precio anterior del articulo");
precant=nuevo.nextDouble();
System.out.println("Ingrese el precio actual del producto");
precact=nuevo.nextDouble();
porcentaje=((precact-precant)/precant)*100;
System.out.println("articulo"+" "+artic);
System.out.println("precio actual"+" "+precact);
System.out.println("precio anterior"+" "+precant);
System.out.println("la inflacion del producto es"+" "+porcentaje+"%");
}
}

Das könnte Ihnen auch gefallen