Programas de c#
Algoritmos y Lenguajes de Programación
Ing. Edmundo Ollervides Valdez
Trabajos de C#
Joel Cumplido Pulido 09130984
24/Noviembre/2010
Pitagoras
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Pitagoras_mejorado
{
class Program
{static void Main(string[] args)
{
int x = 1, y = 1, z = 0;
Console.WriteLine("\tz \tx \ty");
Console.WriteLine("_________________________________");
while (x <= 50)
{
z = (int)Math.Sqrt(x * x + y * y);
while (y <= 50 && z <= 50)
{
if (z *z == x * x + y * y)
Console.WriteLine("\t" + z + "\t" + x + "\t" + y);
y = y + 1;
z = (int)Math.Sqrt(x * x + y * y);
}
x = x + 1;
y = x;
}
Console.ReadLine();
}
}
}
Bucles anidados
using System;
using System.Collections.Generic;using System.Linq;
using System.Text;
namespace bucles_anidados
{
class Program
{
static void Main(string[] args)
{
int i = 1, j = 1;
while (i <= 3)
{
Console.Write("Para i= " + i + ", ");
while (j <= 4)
{
Console.Write("j= " + j + ", ");j++;
}
Console.WriteLine();
i++;
j = 1;
}
Console.ReadLine();
}
}
}
Leer n numerous y sumarlos
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Leer_n_numeros_y_sumarlos
{
class Program
{
static voidMain(string[] args)
{
int n = 0, suma = 0, i = 1, num = 0;
Console.WriteLine("¿Cuantos numeros se van a sumar?:");
n=Int32.Parse(Console.ReadLine());
if (n > 0)
{
suma = 0;
for (i = 1; i <= n; i++)
{
Console.WriteLine("Tecle el numero " + i);num=Int32.Parse(Console.ReadLine());
suma += num;
}
Console.WriteLine("La suma es " + suma);
Console.ReadLine();
}
Console.WriteLine("n es menor que cero");
Console.ReadLine();
}
}
}
Numero Menor
using System;
using System.Collections.Generic;using System.Linq;
using System.Text;
namespace numero_menor
{
class Program
{
static void Main(string[] args)
{
int a = 5, b = 14, c = 1;
if (a < b)
{
if (a < c)
Console.Write("El numero menor es: " + a);
else
Console.Write("El numero menores: " + c);
}
else
{
if (b < c)
Console.Write("El numero menor es: " + b);
else
Console.Write("El numero menor es: " + c);
}
Console.ReadLine();
}
}
}
Suma de 100 números con Do-While
using System;
using System.Collections.Generic;using System.Linq;
using System.Text;
namespace suma_de_100_numeros_con_Do_While
{
class Program
{
static void Main(string[] args)
{
int num = 0, suma = 0, i = 1;
do
{
Console.Write("Cuanto vale el numero " + i + " =");
num = Int32.Parse(Console.ReadLine());
suma += num;...
Regístrate para leer el documento completo.