Está en la página 1de 8

UNIVERSIDAD PRIVADA

ANTENOR ORREGO
FACULTAD DE INGENIERIA
ESCUELA PROFESIONAL DE SISTEMAS Y PROGRAMACIÓN

CURSO:

 ALGORITMIA Y PROGRAMACIÓN

PROFESOR:

 LAZO AGUIRRE, WALTER

ALUMNO:

 LÓPEZ GONZÁLEZ, JORGE ANTONIO

TURNO:

 MIÉRCOLES 8:50 AM – 10:35 AM

TRUJILLO – PERÚ

2022

Trabajo N°5
Algoritmos Repetitivos 2

3. Leer 2 números enteros positivos N1, N2, y hallar reportar su


MCD.
El programa se debe repetir N veces.

Análisis: EFD
N,N1, N2 PROCESO mcd

Implementacion en Java
Diseño de algoritmo
import java.io.*;
public class Main
{public static void main(String[] args)throws IOException
{BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

int c,N,n1,n2,d,mcd;

do{System.out.print("\nIngresar las veces que se repita el programa:");


N=Integer.parseInt(br.readLine());
}
while(N<=0);
for(c=0 ; c<N ; c=c+1)

{ do{System.out.print("\nPrimer numero:");
n1=Integer.parseInt(br.readLine());

}
while(n1<=0);

do{System.out.print("Segundo numero:");
n2=Integer.parseInt(br.readLine());

}
while(n2<=0);

mcd=1;
d=2;
while(d<=n1 || d<=n2)

{if( n1%d==0 && n2%d==0 )


Resultados
{n1=n1/d;
n2=n2/d;
mcd=mcd*d;
}
else
{d=d+1;
}
}
System.out.println("\nel maximo como un divisor:"+mcd);
}
Análisis: EFD

N,ed,Not,Sex PROCESO Cmu, cho,cma,chd

edp, epm
Implementacion en Java

import java.io.*;
public class Main {
public static void main(String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

int N, c=1, ed, cmu=0, cho=0, cma=0, chd=0;

double Not, seph=0, sepm=0, eph=0, epm=0;

String Sex;

do {
System.out.println("Ingresa la cantidad de alumnos");
N = Integer.parseInt(br.readLine());

}while (N<=0);

do {
do {
System.out.println("Elije el sexo del "+c+"° alumno");
System.out.println("Ingresa 'M' para el sexo MASCULINO");
System.out.println("Ingresa 'F' para el sexo FEMENINO");
Sex = br.readLine().toUpperCase();

}while (!Sex.equals("M") && !Sex.equals("F"));

if (Sex.equals("M")) cho++;

else cmu++;

do {
System.out.println("Ingresa la nota del "+c+"° alumno");
Not = Integer.parseInt(br.readLine());

}while (Not<0 || Not>20);

if (Not>=11 && Sex.equals("F")) cma++;

if (Not<11 && Sex.equals("M")) chd++;

do {
System.out.println("Ingresa la edad del "+c+"° alumno");

ed = Integer.parseInt(br.readLine());

}while (ed<=0);
Resultados
if (Sex.equals("M")) {
seph = seph+ed;
eph = seph/N;
}
else {
sepm = sepm + ed;
epm = sepm/N;
}

c++;
}while (c<=N);

System.out.println("De los "+N+" se obtuvo lo siguiente:");


System.out.println("Catidad de mujeres: "+cmu);
System.out.println("Cantidad de hombres: "+cho);
a) Cantidad de mujeres.
b) Cantidad de Hombres. c) Ca
tidad de Mujeres aprobadas. d) Canti
ad de Hombres desaprobados. f
Edad promedio de Hombr
es
7. L eer N pares de números enteros N1, N2 (que pueden ser
positivos, negativos o cero) y
calcular para cada par de números el producto de N1*N2 por sumas
sucesivas.
Análisis: EFD

N1,N2 PROCESO pro

Implementacion en Java

import java.io.*;
public class Main
Diseño de algoritmo
{public static void main(String[]args)throws IOException
itmo
{BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));

int n1,n2,n,c,pro=0;

System.out.print("\nIngresar el primer número:");


n1=Integer.parseInt(br.readLine());

System.out.print("Ingresar el segundo número:");


n2=Integer.parseInt(br.readLine());

if(n2<0)
{n=-n2;}

else
{n=n2;}

for(c=0;c<n;c=c+1)
{pro=pro+n1;}

if(n2<0)
{pro=pro*(-1);}

System.out.print("\nEl promedio es:"+pro);


Resultados
}
}
8. Leer un número N entero positivo. Si N es primo, calcular su
factorial, en caso contrario
descomponerlo en sus factores primos.

Análisis: EFD

N PROCESO fac

Implementacion en Java
Diseño de algoritmo

import java.io.*;
public class Main
{public static void main(String[]args)throws IOException
{BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));

int fac=1,n1,c1,c2,cdv,d=2;

do{System.out.print("\nIngresar el numero:");
n1=Integer.parseInt(br.readLine());}

while(n1<=0);
cdv=0;

for(c2=1;c2<=n1;c2++)

{ if(n1 % c2==0)
{cdv=cdv+1;}}

if(cdv==2)
{for(c1=1;c1<=n1;c1++)
{fac=fac*c1;}

System.out.println("\nEl facotrial es:"+fac);}


else
{while(n1>1)
{if(n1%d==0)
Resultados
{System.out.println("\nSus factores primos son:"+d);
n1=n1/d;}
else
{d=d+1;
}
}
}
}
}

También podría gustarte