jueves, 15 de octubre de 2009

PRACTICA PARA SUMAR IMPARES DE N



PRACTICA PARA SUMAR IMPARES DE UN NUMERO N
CONSOLA

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace suma_de_impares_consola

{

class Program

{

static void Main(string[] args)

{

double N,I,SUMA = 0;

Console.WriteLine("\n\n\t\tINTRODUCE UN NUMERO ");

N = double.Parse(Console.ReadLine());

for (I = 1; I <= N; I = I + 2)

{

SUMA = SUMA + I;

}

Console.WriteLine("\n\n\n\t\tLA SUMA DE LOS IMPARES ES: {0} ", SUMA);

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 suma_de_num_impares_visual

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

double NUM, I, SUMA = 0;

NUM = double.Parse(textBox1.Text);

for (I = 1; I <= NUM; 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