sábado, 24 de octubre de 2009

PRACTICA 6 PROBLEMA 2




namespace PRACTICA_6._2_CONSOLE
{
class Program
{
static void Main(string[] args)
{
double n, i, suma = 0;
Console.WriteLine("\n\nINTRODUCE UN NUMERO");
n = double.Parse(Console.ReadLine());
for (i = 1; i <= n; i = i + 2) { suma = suma + i; } Console.WriteLine("\n\nLA SUMA DE LOS IMPARES ES: {0} ", suma); Console.ReadLine();




PRACTICA EN WINDOWS



namespace PRACTICA_6._2_WINDOWS
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
double n, i, suma = 0;
n = double.Parse(textBox1.Text);
for (i = 1; i <= n; i = i + 2) { suma = suma + i; } textBox2.Text = suma.ToString(); } private void button2_Click(object sender, EventArgs e) { textBox1.Clear(); textBox2.Clear(); } private void button3_Click(object sender, EventArgs e) { Close(); }

No hay comentarios:

Publicar un comentario