lunes, 19 de octubre de 2009

SUMA DE IMPARES

FLUJO


CONSOLA


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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(); } } }


WINDOWS


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 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(); } private void textBox2_TextChanged(object sender, EventArgs e) { } } }

No hay comentarios:

Publicar un comentario