Académique Documents
Professionnel Documents
Culture Documents
using System;
namespace Ejercicios
{
class Ejercicio1
{
while (i < 5)
{
Console.Write("Ingrese {0} nmero:", i + 1);
num = float.Parse(Console.ReadLine());
acu += num;
i++;
}
Console.Write("El promedio de los 5 nmeros es {0}", acu / 5);
Console.Read();
}
}
2) Ingresar un nmero y mostrar el cuadrado del mismo.El nmero debe ser mayor
que cero, en caso de error que aparezca el mensaje "ERROR. Reingresar numero"
using System;
namespace Ejercicios // <--- en otros ejercicios me olvide de ponerlo, pero igualmente por el
momento no son necesarios.
{
class Ejercicio2
{
static void Main()
{
float num;
Console.Write("Ingrese un nmero:");
num = float.Parse(Console.ReadLine());
using System;
class Ejercicio3
{
static void Main()
{
float numero;
uint cont = 0, menor = 0, mayor = 0;
while (cont < 10)
{
Console.Write("Ingrese nmero:");
numero = float.Parse(Console.ReadLine());
if (numero > 0)
mayor++;
if (numero < 0)
menor++;
cont++;
using System;
class Ejercicio
{
static void Main()
{
float radio;
Console.Write("Ingrese radio:");
radio = float.Parse(Console.ReadLine());
using System;
class Ejercicio
{
static void Main()
{
float bas,alt;
Console.Write("Ingrese base:");
bas = float.Parse(Console.ReadLine());
Console.Write("Ingrese altura:");
alt = float.Parse(Console.ReadLine());
* 2.12);
Console.Read();
}
}
10) Ingresar una frase no mas de 20 caracteres y mostrar cuantas vocales tiene.
Cdigo: [Seleccionar]
using System;
class ejercicio
{
static void Main()
{
string letra;
uint a =0, e =0, i =0, o =0, u = 0;
11) Mostrar en pantalla la opcin que se eligio, teniendo en cuenta los dias de la
semana y pregutnar si desea continuar.
Cdigo: [Seleccionar]
using System;
class ejercicio
{
static void Main()
{
string opcion , seguir;
do
{
Console.WriteLine("\nDias de la
semana...\n\n1.Lunes\n2.Martes\n3.Miercoles\n4.Jueves\n5.Viernes\n6.Sabado\n7.D
omingo\n\n");
Console.Write("Ingrese opcin:");
opcion = Console.ReadLine();
if (opcion == "1")
Console.Write("--------------if (opcion == "2")
Console.Write("--------------if (opcion == "3")
Console.Write("--------------if (opcion == "4")
Console.Write("--------------if (opcion == "5")
Console.Write("--------------if (opcion == "6")
Console.Write("--------------if (opcion == "7")
Console.Write("---------------
|Lunes\n");
|Martes\n");
|Miercoles\n");
|Jueves\n");
|Viernes\n");
|Sabado\n");
|Domingo\n");
12)
13)
14)
15)
16)
17)
Mostrar
Mostrar
Mostrar
Mostrar
Mostrar
Mostrar
los
los
los
los
los
los
Cdigo: [Seleccionar]
using System;
class ejercicio
{
static void Main()
{
int i, impar = 0, par = 0;
for (i = 0; i < 100; i++)
{
if (i % 2 != 0)
{
Console.Write("{0}|", i);
impar++;
}
}
Console.Write("\n\n");
// EJERCICIO 13 ////////////////////////////////////
for (i = 1; i < 100; i++)
{
if (i % 2 == 0)
{
Console.Write("{0}|", i);
par++;
}
}
Console.Write("\n\nDel 0 al 100 hay {0} nmeros pares y {1} impares\n\n",
par, impar);
// EJERCICIO 14 /////////////////////////////////////
for(i= 0;i<101;i++)
Console.Write("{0}|",i);
Console.Write("\n\n");
// EJERCICIO 15 ///////////////////////////////////////
for (i = 100; i > -1; i--)
Console.Write("{0}|", i);
Console.Write("\n\n");
// EJERCICIO 16 ////////////////////////////////////////
for(i = 0; i < 100; i++)
if(i % 3 == 0)
Console.Write("{0}|",i);
Console.Write("\n\n");
// EJERCICIO 17 /////////////////////////////////////////
for (i = 0; i < 100; i++)
if (i % 3 == 0 || i % 2 == 0)
Console.Write("{0}|", i);
Console.Read();
}
}
18)
19)
20)
21)
Cdigo: [Seleccionar]
using System;
class ejercicio
{
static void Main()
{
int num, suma = 0, n, divisor,cont = 0;
Console.Write("Nmero:");
num = Int32.Parse(Console.ReadLine());
for (int i = 0; i < num; i++)
suma = suma + i;
Console.Write("La suma de los nmeros que anteceden a el {0} es {1}\n\n",
num, suma);
// EJERCICIO 19 ///////////////////////////////////////////////////////////////////////
for (int i = 1; i < num + 1; i++)
Console.Write("{0}|", i);
// EJERCICIO 20 //////////////////////////////////////////////////////
for(int i = 0; i < num;i++)
if(i % 3 ==0)
cont++;
Console.WriteLine(Entre el 1 y el {0} hay {1} multiplos de 3",num,cont);
//EJERCICIO21 //////////////////////////////////////////////////////////////////////
22) Ingresar
23) Ingresar
24) Ingresar
25) Ingresar
y - de 80.
Cdigo: [Seleccionar]
using System;
class ejercicio
{
static void Main()
{
float num, may0=0, men0=1,x=0;
int cont = 0;
float num1, num2, auxi;
while (cont < 10)
{
do
{
Console.Write("Nmero:");
num = float.Parse(Console.ReadLine());
} while (num == 0);
if (num > 0)
may0 = may0 + num;
if (num < 0)
men0 = men0 * num;
cont++;
}
if (men0 == 1)// En caso de que se ingrese todos +
men0 = 0;
Console.Write("La suma de los nmeros + es {0} y el producto de los - es
{1}", may0, men0);
// EJERCICIO 23 /////////////////////////////////////////////////////////////////////////////
Console.Write("\n\nNmero 1:");
num1 = float.Parse(Console.ReadLine());
Console.Write("Nmero 2:");
num2= float.Parse(Console.ReadLine());
auxi = num1;
num1 = num2;
num2 = auxi;
Console.Write("El nmero 1 ahora es {0} y el nmero 2 es {1}\n\n", num1,
num2);
// EJERCICIO 24 ////////////////////////////////////////////////////////////////////////////
Console.Write("Nmero:");
num1 = float.Parse(Console.ReadLine());
Console.Write("El cuadrado de {0} es {1} y de su cubo es {2}\n", num1,
num1 * num1, num1 * num1 * num1);
// EJERCICIO 25 ///////////////////////////////////////////////////////////////////////////////////////
cont = 0;
men0 = 0;
may0 = 0;
do
{
Console.Write("\nIngrese peso:");
num1 = float.Parse(Console.ReadLine());
if (num1 > 0)
{
if (num1 <= 80)
men0 = men0 + 1;
if (num1 > 80)
may0 = may0 + 1;
cont++;
}
else
Console.Write("\nDebe ingresar mayor a 0\n");
Console.Write("\nDesea continuar s/n ?");// VALIDAR
} while (Console.ReadLine() == "s");
Console.Write("\n\nDe {0} persona/s {1} pesan menos o igual a 80 y {2}
pesan mas de 80",cont,men0,may0);
Console.Read();
}
}
26) Ingresar 3 datos y decir que clase de triangulo es. Para formar un triangulo hay
que tener en cuenta que la suma de sus dos las inferiores
tiene que ser mayor a el lado superior
Cdigo: [Seleccionar]
using System;
namespace ejercicio
{
class ejercicio25
{
static void Main()
{
float[] lado = new float[3];
float mayor = 0, sumar = 0;
int i,j,auxi=0,flag=0;
for (i = 0; i < 3; i++)
{
Console.Write("Lado {0}:",i+1);
lado[i] = float.Parse(Console.ReadLine());
if(lado[i] > mayor)
{
mayor = lado[i];
auxi = i;
}
}
for(i=0;i<3;i++)
if(auxi!= i)
sumar+= lado[i];
if (mayor < sumar)
{
Console.Write("Es un triangulo");
for (i = 0; i < 2; i++)
for (j = i + 1; j < 3; j++)
if (lado[i] == lado[j])
flag++;
if (flag == 3)
Console.Write(" ---> Equilatero");
else
{
flag = 0;
for (i = 0; i < 2; i++)
for (j = i + 1; j < 3; j++)
if (lado[i] != lado[j])
flag++;
if (flag == 3)
Console.Write(" ---> Escaleno");
else
Console.Write(" ---> Isosceles");
}
}
else
{
Console.Write("No es un triangulo");
}
Console.Read();
}
}
}
Cdigo: [Seleccionar]
using System;
class ejercicio26
{
static void Main()
{
float[] numero = new float[3];
float mayor = 0, menor = 0;
int i, flag = 0,noingreso = 0;
for (i = 0; i < 3; i++)
{
Console.Write("{0} nmero:", i + 1);
numero[i] = float.Parse(Console.ReadLine());
if (flag == 0)
{
mayor = numero[i];
menor = numero[i];
flag = 1;
}
else
{
if (numero[i] > mayor)
mayor = numero[i];
if (numero[i] < menor)
menor = numero[i];
}
}
for (i = 0; i < 3; i++)
{
if (numero[i] != mayor && numero[i] != menor)
{
Console.Write("\nEl nmero {0} esta entre el {1} y el {2}", numero[i],
menor, mayor);
noingreso = 1;
}
}
if (noingreso == 0)
Console.Write("\nError.Hay numeros repetidos");
Console.Read();
}
}
30)Ingresar 2 nmeros, imprima los nmeros naturales que hay entre ambos
empezando por el ms pequeo, contar cuntos nmeros hay y cuntos de ellos
son pares.
Cdigo: [Seleccionar]
using System;
namespace ejercicio
{
class ejercicio29
{
static void Main()
{
float num1, num2, menor, mayor;
int i, cont = 0, contpar = 0;
do
{
Console.Write("Nmero 1:");
num1 = float.Parse(Console.ReadLine());
Console.Write("Nmero 2:");
num2 = float.Parse(Console.ReadLine());
} while (num1 == num2);
if (num1 < num2)
{
menor = num1;
mayor = num2;
}
else
{
menor = num2;
mayor = num1;
}
for (i = (int)menor + 1; i < mayor; i++)
{
Console.Write("{0}|", i);
cont++;
if (i % 2 == 0)
contpar++;
}
if(num1 == num2-1 || num2 == num1-1)
Console.Write("\n\nNo hay numeros enteros entre {0} y el
{1}",num1,num2);
else
Console.Write("\n\nEntre {0} y {1} hay {2} nmeros de los cuales {3}
son pares", menor, mayor, cont, contpar);
Console.Read();
}
}
}
op[i] = int.Parse(Console.ReadLine());
}
Console.WriteLine();
for (i = 0; i < 10; i++)
{
if (op[i] == 1 && sueldo[i] > 500 || op[i] == 2 && sueldo[i] < 400)
Console.WriteLine("Legajo: {0}|Sexo: {1}|Sueldo: {2}", legajo[i], op[i],
sueldo[i]);
}
Console.Read();
}
}
}
32)Se ingresa por teclado la cantidad de agua caida, en mlimetros da a da
durante un mes.Se pide determinar el da de mayor lluvia, el de menor y el
promedio.
Cdigo: [Seleccionar]
using System;
namespace ejercicio
{
class ejercicio31
{
static void Main()
{
int flag = 0,i = 0, mayordia = 0, menordia = 0, x = 30;
int[] dia = new int[31];
float menor = 0, mayor = 0, promedio = 0,contagua = 0;
float[] agua = new float[x + 1];
do
{
Console.Write("Ingrese dia:");
dia[i] = int.Parse(Console.ReadLine());
Console.Write("Ingrese agua caida:");
agua[i] = float.Parse(Console.ReadLine());
if (flag == 0)
{
mayordia = dia[i];
menordia = dia[i];
mayor = agua[i];
menor = agua[i];
flag = 1;
}
else
{
if (agua[i] > mayor)
{
mayordia = dia[i];
mayor = agua[i];
}
if (agua[i] < menor)
{
menordia = dia[i];
menor = agua[i];
}
}
contagua+= agua[i];
if(i == 29)
{ Console.Write("El mes tiene 31 dias s/n ?");
if(Console.ReadLine() == "s")
x = x + 1;
}
i++;
}while(i<x);
promedio = contagua / i;
if (menor == mayor)
{
Console.Write("\nNo hubo mayor y menor dia de agua caida, fue igual
para todos los dias {0}", menor);
}
else
{
Console.WriteLine("\nLa mayor cantidad de agua caida fue de {0}
milmetros el/los dia/s ...", mayor);
33) Hacer el algoritmo que imprima el mayor y el menor de una serie de 5 nmeros
que vamos introduciendo por teclado.
Cdigo: [Seleccionar]
using System;
namespace ejercicio
{
class ejercicio32
{
static void Main()
{
float[] num = new float[5];
float mayor = 0, menor = 0;
int flag = 0;
for (int i = 0; i < 5; i++)
{
Console.Write("Ingrese {0} nmero:", i + 1);
num[i] = float.Parse(Console.ReadLine());
if (flag == 0)
{
mayor = num[i];
menor = num[i];
flag = 1;
}
else
{
if (num[i] > mayor)
mayor = num[i];
if (num[i] < menor)
menor = num[i];
}
}
if (mayor == menor)
Console.Write("\nLos nmeros son todos iguales\n");
else
Console.Write("\nEl menor de los 5 nmeros es el {0} y el mayor es el
{1}", menor, mayor);
Console.Read();
}
}
}
Bueno despues posteare los que restan. Saludos.
Bueno aqu dejo el codigo, puede resultar confuso pero bue es como para ir tirando
la idea.
Cdigo: [Seleccionar]
using System;
using Serializacion_chofer;
namespace programa_principal
{
class principal
{
static void Main()
{
Serializacion chofer = new Serializacion();
chofer.metodo_chofer();
}
}
}
Cdigo: [Seleccionar]
using
using
using
using
using
System;
System.Collections.Generic;
System.Xml.Serialization;
System.IO;
System.Xml;
namespace Serializacion_chofer
{
public class Serializacion
{
String opcion;
int N = 8, idaux;
int flagi;
public void metodo_chofer()
{
List<Chofer> ListaChoferes = new List<Chofer>();
using (XmlTextReader reader = new XmlTextReader("Choferes.xml"))
{
try
{
XmlSerializer ser = new XmlSerializer(typeof(List<Chofer>));
ListaChoferes = (List<Chofer>)ser.Deserialize(reader);
}
catch (InvalidOperationException e)
{
Console.WriteLine("Se crear el archivo");
}
}
do
{
Console.Clear();
Console.BackgroundColor = ConsoleColor.Blue;
Console.CursorLeft = N;
Console.WriteLine("
");
Console.CursorLeft = N;
Console.WriteLine("
MENU
");
Console.CursorLeft = N;
Console.WriteLine("
");
Console.CursorLeft = N;
Console.WriteLine("
1 - Agregar Chofer
");
Console.CursorLeft = N;
Console.WriteLine("
2 - Modificar Chofer
");
Console.CursorLeft = N;
Console.WriteLine("
3 - Eliminar Chofer
");
Console.CursorLeft = N;
Console.WriteLine("
4 - Listar Choferes
");
Console.CursorLeft = N;
Console.WriteLine("
5 - Persistir en XML (Guardar los cambios
realizados) ");
Console.CursorLeft = N;
Console.WriteLine("
6 - Busqueda
");
Console.CursorLeft = N;
Console.WriteLine("
7 - Salir
");
Console.CursorLeft = N;
Console.WriteLine("
");
Console.CursorLeft = N;
Console.WriteLine("
* - Ingrese una opcion:
");
Console.CursorLeft = N;
Console.WriteLine("
");
Console.BackgroundColor = ConsoleColor.Black;
Console.SetCursorPosition(41, 11);// Columna, fila
opcion = Console.ReadLine();
Console.Clear();
switch (opcion)
{
case "1":
do
{
flagi = 0;
Console.Clear();
Console.WriteLine("Ingreso de Datos\n");
Chofer miChofer = new Chofer();
idaux = miChofer.CargarChofer();
foreach (Chofer miChoferAux in ListaChoferes)
{
if (miChoferAux.esIgual(idaux))
{
flagi = 1;
Console.Write("\nError debe reingresar los datos, la id ya
existe");
Console.ReadKey();
}
}
if (flagi != 1)
ListaChoferes.Add(miChofer);
} while (flagi == 1);
break;
case "2":
Console.WriteLine("Ingrese Legajo a Modificar");
idaux = Int32.Parse(Console.ReadLine());
Boolean flag = false;
foreach (Chofer miChoferAux in ListaChoferes)
{
if (miChoferAux.esIgual(idaux))
{
miChoferAux.modificar();
flag = true;
}
}
if (!flag)
{
Console.WriteLine("No se Encontr");
}
break;
case "3":
Console.WriteLine("Ingrese ID a Borrar");
idaux = Int32.Parse(Console.ReadLine());
flag = false;
for (int i = 0; i < ListaChoferes.Count; i++)
{
if (ListaChoferes[i].esIgual(idaux))
{
Console.Write("\nDatos a borrar\n\nID: {0}|Nombre: {1}|
Apellido: {2}", ListaChoferes[i].id, ListaChoferes[i].Nombre,
ListaChoferes[i].Apellido);
Console.ReadKey();
ListaChoferes.RemoveAt(i);
flag = true;
}
}
if (!flag)
{
Console.WriteLine("\nNo se Encontr");
Console.ReadKey();
}
break;
case "4":
foreach (Chofer miChoferAux in ListaChoferes)
{
miChoferAux.Mostrar();
}
Console.ReadLine();
break;
case "5":
using (XmlTextWriter writer = new XmlTextWriter("Choferes.xml",
System.Text.Encoding.UTF8))
{
XmlSerializer ser = new XmlSerializer(typeof(List<Chofer>));
ser.Serialize(writer, ListaChoferes);
writer.Close();
}
break;
case "6":
Console.WriteLine("Ingrese ID a Borrar");
idaux = Int32.Parse(Console.ReadLine());
flag = false;
for (int i = 0; i < ListaChoferes.Count; i++)
{
if (ListaChoferes[i].esIgual(idaux))
{
Console.Write("\nDatos\n\nID: {0}|Nombre: {1}|Apellido: {2}",
ListaChoferes[i].id, ListaChoferes[i].Nombre, ListaChoferes[i].Apellido);
Console.ReadKey();
ListaChoferes.RemoveAt(i);
flag = true;
}
}
if (!flag)
{
Console.WriteLine("\nLos datos no se encontraron");
Console.ReadKey();
}
break;
case "7":
break;
default:
Console.WriteLine("Error. Opcion Incorrecta");
Console.ReadKey();
break;
}
} while (opcion != "7");
}
}
}
Cdigo: [Seleccionar]
using System;
namespace Serializacion_chofer
{
public class Chofer
{
public Int32 id;
public String Nombre, Apellido;
public int CargarChofer()
{
Console.WriteLine("Ingrese ID");
id = Int32.Parse(Console.ReadLine());
Console.WriteLine("Ingrese Nombre");
Nombre = Console.ReadLine();
Console.WriteLine("Ingrese Apellido");
Apellido = Console.ReadLine();
return id;
}
public void Mostrar()
{
Console.WriteLine("ID:{0} APELLIDO:{1} NOMBRE: {2}", id, Apellido,
Nombre);
}
public Boolean esIgual(Int32 identificador)
{
if (identificador == id)
return true;
else
return false;
}
public void modificar()
{
Console.WriteLine("Ingrese Nombre");
Nombre = Console.ReadLine();
Console.WriteLine("Ingrese Apellido");
Apellido = Console.ReadLine();
}
}
}