20091021

PRACTICA 7.2 CALCULO Y SUMA DE NUEMROS PAR DE 2 HASTA N. (visual)






Diseñe un programa que le permita leer un numero N par, y calcule e imprima la suma de los números pares del 2 hasta el numero leído, si el numero leído es menor que 2,


A continuacion elejecutable de forma 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 WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
double n, I, x = 0.0;

n = int.Parse(textBox1.Text);
if (n <> 2)
{
for (I = 2; I <= n; I = I + 2) { listBox1.Items.Add("" + I.ToString()); x = x + I; } textBox2.Text = ("La suma de los numeros pares es " + x.ToString()); { } } } private void button2_Click(object sender, EventArgs e) { textBox1.Clear(); textBox2.Clear(); listBox1.Items.Clear(); } private void button3_Click(object sender, EventArgs e) { Close(); } } }


No hay comentarios:

Publicar un comentario