EXAMEN 3 INCISOS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace examen_3_incisos
{
class Matematicas
{
//sumatoria
public int Sumatoria(int n)
{
if (n == 0 || n == 1)
return n;
else
return n % 10 + Sumatoria(n / 10);
}
//fabinucci
public int fibonacci_iter(int n)
{
int suma = 0, fib = 1, fib2 = 0;
for (int i = n - 1; i > 0; i--)
{
suma = fib + fib2;
fib2 = fib;
fib = suma;
}
return suma;
}
}
}
========================================================
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace examen_3_incisos
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
textPalabraInv.Visible = false;
textPalInvertida.Visible = false;
butInvertir.Visible = false;
textNumSuma.Visible = false;
textResultSuma.Visible = false;
butsuma.Visible = false;
textNumFabi.Visible = false;
textResulFabi.Visible = false;
butFabinucci.Visible = false;
groupBox2.Visible = false;
}
Cadena palabra = new Cadena();
private void butInvertir_Click(object sender, EventArgs e)
{
try
{
string pal = Convert.ToString(textPalabraInv.Text);
textPalInvertida.Text = Convert.ToString(palabra.Invertir(pal));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Matematicas mate = new Matematicas();
private void butsuma_Click(object sender, EventArgs e)
{
try
{
int sum = Convert.ToInt32(textNumSuma.Text);
int[] res = new int[(int)sum];
textResultSuma.Text = Convert.ToString(mate.Sumatoria(sum));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void butFabinucci_Click(object sender, EventArgs e)
{
try
{
int fab = Convert.ToInt32(textNumFabi.Text);
textResulFabi.Text = Convert.ToString(mate.fibonacci_iter(fab));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void radioInvertir_CheckedChanged(object sender, EventArgs e)
{
textNumSuma.Visible = false;
textNumSuma.Text = "";
textResultSuma.Visible = false;
textResultSuma.Text = "";
butsuma.Visible = false;
textNumFabi.Visible = false;
textNumFabi.Text = "";
textResulFabi.Visible = false;
textResulFabi.Text = "";
butFabinucci.Visible = false;
groupBox2.Visible = false;
}
private void radioSumatoria_CheckedChanged(object sender, EventArgs e)
{
textPalabraInv.Visible = false;
textPalabraInv.Text = "";
textPalInvertida.Visible = false;
textPalInvertida.Text = "";
butInvertir.Visible = false;
textNumFabi.Visible = false;
textNumFabi.Text = "";
textResulFabi.Visible = false;
textResulFabi.Text = "";
butFabinucci.Visible = false;
groupBox2.Visible = false;
}
private void radioFabinucci_CheckedChanged(object sender, EventArgs e)
{
textPalabraInv.Visible = false;
textPalabraInv.Text = "";
textPalInvertida.Visible = false;
textPalInvertida.Text = "";
butInvertir.Visible = false;
textNumSuma.Visible = false;
textNumSuma.Text = "";
textResultSuma.Visible = false;
textResultSuma.Text = "";
butsuma.Visible = false;
groupBox2.Visible = false;
}
private void OK_Click(object sender, EventArgs e)
{
if (radioInvertir.Checked)
{
textPalabraInv.Visible = true;
textPalInvertida.Visible = true;
butInvertir.Visible = true;
groupBox2.Visible = true;
}
else
if (radioSumatoria.Checked)
{
textNumSuma.Visible = true;
textResultSuma.Visible = true;
butsuma.Visible = true;
groupBox2.Visible = true;
}
else
if (radioFabinucci.Checked)
{
textNumFabi.Visible = true;
textResulFabi.Visible = true;
butFabinucci.Visible = true;
groupBox2.Visible = true;
}
}
}
}
EXAMEN PARTE 2 CONSOLA
Esta aplicacion es del examen Unidad 2 de recursividad en el cual muestra una multiplicacion de 2 numeros enteros y el triangulo de pascal usando un metodo recursivo
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace Examen_UII_Recursividad___Parte_2__Consola_
{
class Program
{
//EXAMEN 1
public static int
Multiplicacion(int a, int
b)
{
if
(a == 0 || b == 0)
return
0;
else
return
a + Multiplicacion(a, b - 1);
}
//EXAMEN 2
public static int Exa2(int n, int r)
{
if
(n == 0 || n == 1 || r == 0 || n == r)
return
1;
else
{
return
Exa2(n - 1, r) + Exa2(n - 1, r - 1);
}
}
static void Main(string[]
args)
{
//EXAMEN
1
int
resul = Multiplicacion(6, 6);
Console.WriteLine(resul);
Console.ReadKey();
Console.Clear();
//EXAMEN
2
for
(int i = 0; i <= 6; i++)
{
for
(int ii = 0; ii <=i; ii++)
Console.WriteLine(Exa2(i,
ii) + " ");
Console.WriteLine();
}
Console.ReadKey();
}
}
}
EXAMEN PARTE 2 VISUAL
Esta aplicacion es similar al consola, solo qe ahora esta hecha en visual.
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
namespace Examen_UII_Recursividad___Parte_2
{
public partial class Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
//EXAMEN 1
public static int
Multiplicacion(int a, int
b)
{
if
(a == 0 || b == 0)
return
0;
else
return
a + Multiplicacion(a, b - 1);
}
//EXAMEN 2
public static int Exa2(int n, int r)
{
if
(n == 0 || n == 1 || r == 0 || n == r)
return
1;
else
{
return
Exa2(n - 1, r) + Exa2(n - 1, r - 1);
}
}
private
void butMultiplicar_Click(object sender, EventArgs
e)
{
try
{
int
a = Convert.ToInt32(txtValA.Text);
int
b = Convert.ToInt32(txtValB.Text);
txtResul.Text = Convert.ToString(Multiplicacion(a, b));
}
catch
(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private
void butCalcular_Click(object
sender, EventArgs e)
{
int
pa = Convert.ToInt32(txtPA.Text);
int
pb = Convert.ToInt32(txtPB.Text);
txtResulPascal.Text = Convert.ToString(Exa2(pa,
pb));
}
}
}
No hay comentarios:
Publicar un comentario