Factorial - for - while - do while




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Factorial_E_Repetitivas
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Application.Exit();
}

private void button2_Click(object sender, EventArgs e)
{
int n, f = 1;
n = int.Parse(textBox1.Text);
for (int i=1; i<= n; i++)
{
f *= i;
textBox2.Text = f.ToString();
}
}



private void button3_Click(object sender, EventArgs e)
{
int n, f = 1, i = 1;
n = int.Parse(textBox1.Text);
while (i <= n)
{
f *= i;
i++;
textBox3.Text = f.ToString();
}
}



private void button4_Click(object sender, EventArgs e)
{
int n, f = 1, i = 1;
n = int.Parse(textBox1.Text);
do
{
f *= i;
i++;
}
while
(i <= n);
textBox4.Text = f.ToString();
}
}
}

No hay comentarios:

Publicar un comentario

Nota: solo los miembros de este blog pueden publicar comentarios.