Está en la página 1de 13

UNIVERSIDAD PRIVADA

DOMINGO SABIO

UNIVERSIDAD PRIVADA DOMINGO SABIO


FACULTAD DE CIENCIAS EMPRESARIALES
MATERIA: programación 1 Turno: Noche 20/08/2021
DOCENTE: Hernán rodríguez
DATOS DEL ESTUDIANTE
Apellido Paterno, Quiroz Guzmán Ricardo
Materno y Nombres
Nombre de la Actividad: practico1
Carrera: Ingeniería en sistema
Fecha de entrega: 20/08/2021
Ing. Hernán Rodríguez C. UPDS

TRABAJO PRACTICO

ESTRUCTURAS DE CONTROL EN ALGORITMOS

I. CONSTRUYA LOS SIGUIENTES ALGORITMOS: REALICE EL ESQUEMA DE ANALISIS, PSEUDOCÓDIGO,


PRUEBA DE ESCRITORIO Y LENGUAJE C#:
1. Devuelva la cantidad de dígitos pares de un numero natural

ANALISIS
pseudocódigo
58316 mientras (n>0)
Algoritmo: suma de dígitos
8 6 dig=n modulo 10
Inicio
2 1 res= dig modulo 2
Numero entero: N,dig,cont,res;
Si (res==0)
Leer N;
Cont=cont++
Dig= 0;
N=n/10
Res=0;
Mientras (N>0)
Inicio
Digito =N mod 10;
Res=dig mod 2
Prueba de escritorio
N dig res cont
Si(res==0)

58316 6 0 1 Inicio

5831 1 1 Cont=cont+1

583 3 1 2 Fin

58 8 0 N=N/10
5 5 1 Fin
0 escribir cont
Fin
Lenguajec#
static void Main(string[] args)

int n= int.Parse(Console.ReadLine());

int digito = 0;

int cont = 0;

int resi = 0;

do

digito = n % 10;

resi = digito % 2;

if (resi == 0)

cont = cont + 1;

n = n / 10;

while (n > 0);

Console.WriteLine(cont);

Console.ReadKey();

N= 58316
2. Ordene de forma descendente los dígitos de un numero natural n

pseudocódigo
ANALISIS
Algoritmo: ordenar dígitos descendente
N=5 8 3 1 6 -9 m=(m*10)*dig
Inicio
5 8 3 1 6 -8 m=86531
Numero entero: n,m,cont,dig,aux;
Dig=n modulo 10
Leer N;

Cont=9;

M=0;

Aux=N;

Inicio

Mientras(n>0)

Inicio

Dig=N modulo 10;


Prueba de escritorio
Si (dig==cont)
N M cont dig aux
Inicio
789 0 9 789
M=(M*10)+dig;
9 8 9
Fin
789 9
N=N/10;
78 98 8

789 7 9
Fin
78 8
Cont=cont-1;
7 987 7
N=aux;
0
Fin

Escribir M

fin
Lenguaje C#
int n, m, cont, dig, aux;

Console.WriteLine("por favor infresar un numero


natural");

n = int.Parse(Console.ReadLine());

cont = 9;

m = 0;

aux = n;

while (cont>= 0)

while(n>0)

dig = n % 10;
LENGUAJE C#
if(dig==cont)

m = (m * 10) + dig;

n = n / 10;

cont = cont - 1;

n = aux;

Console.WriteLine("el resultado es:");

Console.WriteLine(m);

Console.ReadKey();
N= 58316

M= 86531 (descendente)
3. Retorne el digito menor de un numero natural

pseudocódigo
ANALISIS Algoritmo: mostrar dígitos menor

831 dig=N modulo 10 Inicio

831 menor= N modulo 10 Numero entero: n, dig,menor;

1 Leer N;

Menor=1 dig=0;

menor=N modulo 10;

hacer

inicio

dig= N modulo 10;

si (dig<menor)

inicio

Prueba de escritorio menor=dig;

N dig menor fin

831 0 1 N=N/10;

83 1 Fin

8 3 While(N>0)

0 8 menor Escribir menor

fin
Lenguaje C#
static void Main(string[] args)

int n = int.Parse(Console.ReadLine());

int digito = 0;

int menor = n%10;

do

digito = n % 10;

if (digito < menor)

menor = digito;

n = n / 10;

while (n > 0);

Console.WriteLine(menor);

Console.ReadKey();

N= 58316
men= 1
4. Elimine los dígitos repetidos de un numero natural pseudocódigo
Algoritmo: eliminar dígitos repetidos

ANALISIS Inicio

5 4 5 4 4 2 dig Numero entero: n,


dig,rep,M,mult,dig2,cop,aux;
5 4 5 4 4 2 rep
Leer N;
232331
M=0;
Si(rep==1)
Mult=1;
M=2
Cop=N;

Mientras(N>0)

Inicio

Dig=N modulo 10;

Rep=0;

Prueba de escritorio Aux=cop;

N dig dig2 rep mult cop aux M Mientra(aux > 0)

2325 2 1 232 0 Inicio

23 0 Dig2=aux modulo 10;

2 232 Si(dig=dig2)

3 3 1 23 Inicio

2 2 2 Rep=rep+1;

- - - - - 0 Fin

2 232 Aux=aux/10;

Fin
N=3 5455121
1 23

2 2 Si(rep==1)
M= 42
O Inicio

232 M=(dig*mult)+M;

Mult=mult*10;

Fin
831 0 1 N=n/10;
83 1 Fin
8 3 Escribir m
0 8

dig=0;

menor=N modulo 10;


Lenguaje c#

Console.WriteLine("por favor ingrezar un numero");

int n = int.Parse(Console.ReadLine());

int M = 0;

int mult = 1;

int COP =N

while (n > 0);

Int dig = n % 10;

Int rep = 0;

Int aux = COP;

While (aux % 0)

int dig2 = aux % 10;

if (dig == dig2)

rep = rep +1;

aux = aux/ 10;

if (rep == 1)

M= (dig*mult)+M:

mult = mult * 10;

n = n / 10;

Console.WriteLine("el resultado es:");

Console.WriteLine(M);
5. Elimine los dígitos pares de un numero natural
static void Main(string[] args)
{
Console.WriteLine("Elimine los dígitos pares de un numero natural");
int n = int.Parse(Console.ReadLine());
int m = 0;
int mult = 1;
while (n > 0)
{
int dig = n % 10;
int resid = dig % 2;
if (resid == 1)
{
m = (dig * mult) + m;
mult = mult * 10;
}
n = n / 10;

}
Console.WriteLine("El resultado es:");
Console.WriteLine(m);
Console.ReadKey();
}
}
}

N= 58316

M= 531
6. Devuelva verdadero si un numero natural tiene dígitos pares, caso contrario
devuelva falso
Console.WriteLine("Elimine los dígitos pares de un numero natural");

Console.WriteLine("por fabor ingrese digitos");

int n = int.Parse(Console.ReadLine());

int sw = 0;

while ((n > 0) & (sw == 0))

int dig = n % 10;

if (dig % 2 == 0)

sw = 1;

n = n / 10;

if (sw == 0)

Console.WriteLine("falso");

Console.ReadKey();

else

Console.WriteLine("el resultado");

Console.WriteLine("verdadero");

Console.ReadKey()

N= 58316 N= 531
sw= verdadero sw= falso

También podría gustarte