Вы находитесь на странице: 1из 3

ALGORITMOS Y ESTRUCTURAS DE DATOS

LABORATORIO N 01
FORMULARIOS Y MTODOS RECURSIVOS

OPERACIONES A IMPLEMENTAR

a) Creacin del formulario principal.


b) Clculo del Residuo Entero de la divisin de dos nmeros por restas sucesivas.
c) Clculo del Producto de dos nmeros por el mtodo del Algoritmo Ruso.

DETALLE DE LAS OPERACIONES

RESIDUO POR RESTAS SUCESIVAS

El Residuo de dos nmeros entero positivos a y b, por el mtodo de restas sucesivas; se obtiene restando el
divisor tantas veces como sea posible al dividendo, mientras el divisor sea mayor o igual al dividendo; as:

Residuo(a, b) = a-b; si a>=b (Repetir hasta que a<b; entonces el resultado estar en a)

ALGORITMO RUSO DEL PRODUCTO

El Producto de dos nmeros entero positivos a y b; se calcula verificando, si a es Par; se divide el valor de a
entre 2 y se duplica el valor de b. Si a es Impar; se divide el valor de a entre 2 (valor entero) y se duplica el
valor de b, agregando el b anterior. As:

a b
36 5
18 10
9 20
4 40 + 20
2 80 + 20
1 160 + 20
180

MG. LUIS BOY CHAVIL Pgina 1


ALGORITMOS Y ESTRUCTURAS DE DATOS

DISEO DEL FORMULARIO

PROGRAMACIN DE LA CLASE OPERACIONES

#pragma once

ref class OPERACIONES


{
public:
int Numero1;
int Numero2;
public:
int Residuo(int, int);
int Producto(int, int);
OPERACIONES(void)
{
}
};

int OPERACIONES::Residuo(int a, int b)


{
if(a>=b)
return(Residuo(a-b, b));
else
return(a);
}

int OPERACIONES::Producto(int a, int b)


{
if(a>1)
{
if(a%2==0)
return(Producto(a/2, 2*b));
else
return(b+Producto(a/2, 2*b));
}
else
return(b);
}

MG. LUIS BOY CHAVIL Pgina 2


ALGORITMOS Y ESTRUCTURAS DE DATOS

PROGRAMACIN DE LAS OPERACIONES DEL MEN EN EL FORMULARIO

Agregue al inicio del programa:

#include "OPERACIONES.h"

private: System::Void BtnResiduo_Click(System::Object^ sender, System::EventArgs^ e)


{
OPERACIONES OP;
OP.Numero1=Convert::ToInt16(TxtNumero1->Text);
OP.Numero2=Convert::ToInt16(TxtNumero2->Text);
if(OP.Numero1>0&&OP.Numero2>0)
{
String^ Resto=Convert::ToString(OP.Residuo(OP.Numero1,
OP.Numero2));
MessageBox::Show("Residuo entero: "+Resto);
}
else
MessageBox::Show("Ingrese valores +");
}
private: System::Void BtnRuso_Click(System::Object^ sender, System::EventArgs^
e)
{
OPERACIONES OP;
OP.Numero1=Convert::ToInt16(TxtNumero1->Text);
OP.Numero2=Convert::ToInt16(TxtNumero2->Text);
if(OP.Numero1>0&&OP.Numero2>0)
{
String^ Produc=Convert::ToString(OP.Producto(OP.Numero1,
OP.Numero2));
MessageBox::Show("Producto entero: "+Produc);
}
else
MessageBox::Show("Ingrese valores +");
}

MG. LUIS BOY CHAVIL Pgina 3

Вам также может понравиться