20091103

PRACTICA 7.5 SUMA DE IMAPRES Y PARES (visual)(consola)

pseudocodigo
inicio
double n
int x
double sumaimpar = 0.0
double sumapar = 0.0
print "INTRODUCE EL NUMERO "
Read n;
for (x = 1 to x <= n step x = x + 1)
{
if (x == 1) sumaimpar = sumaimpar + x;
else { sumapar = sumapar + x;
} }
print "LA SUMA DE LOS NUMEROS IMPARESES: ", sumaimpar print"LA SUMA DE LOS NUMEROS PARES ES ", sumapar
while(sumapar >sumaimpar)
{
print"LA SUMA DE LOS PARES ES MAYOR"
}
fin.










A continuacion el ejecutable de la suma de pares e impares.

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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
double n;
int x;
double sumaimpar = 0.0;
double sumapar = 0.0;
n = int.Parse(textBox1.Text);
for (x = 1; x <= n; x = x + 1) { if (x % 2 == 1)

{
sumaimpar = sumaimpar + x;
}
else
{
sumapar = sumapar + x;
}
} textBox2.Text = ("LA SUMA DE LOS NUMEROS IMPARES ES=" + sumaimpar.ToString()); textBox3.Text = ("LA SUMA DE LOS NUMEROS PARES ES=" + sumapar.ToString()); } } }











PRACTICA 7.5 SUMA DE IMAPRES Y PARES (consola)


EJECUTABLE EN CONSOLA





using System;
using System.Collections.Generic;

class Program
{
static void Main(string[] args)
{
double n;
int x;
double sumaimpar = 0.0;
double sumapar = 0.0;
Console.WriteLine("\tINTRODUCE EL NUMERO ");
n = double.Parse(Console.ReadLine());
for (x = 1; x <= n; x = x + 1) { if (x % 2 == 1)

{

sumaimpar = sumaimpar + x;

} else

{

sumapar = sumapar + x;

}

} Console.WriteLine("\tLA SUMA DE LOS NUMEROS IMPARESES: {0}", sumaimpar); Console.WriteLine("\tLA SUMA DE LOS NUMEROS PARES ES {0}", sumapar);

while(sumapar >sumaimpar)
{
Console.WriteLine("\tLA SUMA DE LOS PARES ES MAYOR");
Console.ReadKey();
}
}
}
}

No hay comentarios:

Publicar un comentario