jueves, 15 de octubre de 2009

PRACTICA 6 FACTORIAL DE UN NUMERO

PRACTICA 6 FACTORIAL DE UN NUMERO

CONSOLA

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FACTORIAL_EN_CONSOLA
{
class Program
{
static void Main(string[] args)
{
double N, I, FACTOR = 1.0;
Console.WriteLine("\n\nINTRODUCE UN NUMERO PARA OBTENER EL VALOR DEL FACTORIAL");
N = double.Parse(Console.ReadLine());
for (I = N; I >= 1; I--)
{
FACTOR = FACTOR * I;
}
Console.WriteLine("\n\tEL FACTORIAL DEL NUMERO ES: {0}", FACTOR);
Console.ReadLine();
}
}
}


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 facotorial_visual
{
public partial class Form1 : Form
{
double FACTOR, N, I;
public Form1()
{
FACTOR = 1.0;
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
double N, I, FACTOR = 1.0;
N = int.Parse(textBox1.Text);
for (I = N; I >= 1; I--)
for (I = N; I >= 1; I--)
{
FACTOR = FACTOR * I;
}
textBox2.Text = FACTOR.ToString();

}

private void button2_Click(object sender, EventArgs e)
{
textBox1.Clear();
textBox2.Clear();
}

private void button3_Click(object sender, EventArgs e)
{
Close();
}

private void Form1_Load(object sender, EventArgs e)
{

}
}
}

No hay comentarios:

Publicar un comentario