domingo, 2 de octubre de 2011

JUEGO DE TRES EN RAYA


using System;
using System.Collections.Generic;
namespace __EnRayas
{
class MainClass
{
public static void Main(string[] args)
{
int[,] matriz = new int [3,3];

LlenandoMatriz(matriz);
Visualizar(matriz);
TresRayas(matriz);

Console.ReadKey(true);
}

public static void LlenandoMatriz (int[,] pMatriz)
{
Random rnd = new Random();

for(int i=0; i<3; i++){
for(int p=0; p<3; p++){
pMatriz[i,p]=rnd.Next(0,2);
}
}
}

public static void Visualizar (int[,] pMatriz)
{
int f=0, c=10;

for(int i=0; i<3; i++){
f=5;
for(int p=0; p<3; p++){
Console.SetCursorPosition(c,f);
Console.WriteLine("{0}",pMatriz[i,p]);
f+=3;
}
c+=5;
}
}
public static void TresRayas (int[,] pMatriz)
{

int a=0, b=0, c=0, d=0, e=0, f=0, h=0, u=0;

for(int i=0; i<3; i++){
a+=pMatriz[0,i];
}
if(a==0||a==3){
Console.SetCursorPosition(10,14);
Console.WriteLine("Tres en rayas Columna 1");
}

for(int j=0; j<3; j++){
b+=pMatriz[1,j];
}
if(b==0||b==3){
Console.SetCursorPosition(10,15);
Console.WriteLine("Tres en rayas Columna 2");
}

for(int j=0; j<3; j++){
c+=pMatriz[2,j];
}
if(c==0||c==3){
Console.SetCursorPosition(10,16);
Console.WriteLine("Tres en rayas Columna 3");
}
for(int j=0; j<3; j++){
d+=pMatriz[j,0];
}
if(d==0||d==3){
Console.SetCursorPosition(10,17);
Console.WriteLine("Tres en rayas Fila 1");
}

for(int j=0; j<3; j++){
e+=pMatriz[j,1];
}
if(e==0||e==3){
Console.SetCursorPosition(11,18);
Console.WriteLine("Tres en rayas Fila 2");
}

for(int j=0; j<3; j++){
f+=pMatriz[j,2];
}
if(f==0||f==3){
Console.SetCursorPosition(10,19);
Console.WriteLine("Tres en rayas Fila 3");
}

int x=2;
while(x>=0){
for(int j=0; j<3; j++){
h+=pMatriz[x,j];
x--;
}
}
if(h==0||h==3){
Console.SetCursorPosition(10,20);
Console.WriteLine("Tres en rayas Diagonal Secundaria  ");
}
int l=0;
while(l<3){
u=u+pMatriz[l,l];
l++;
}
if(u==0||u==3){
Console.SetCursorPosition(10,21);
Console.WriteLine("Tres en rayas Diagonal Primaria  ");
}
}}}

RELOJ DIGITAL CON ALARMA

//Es un reloj digital con alarma:
using System;
using System.Collections.Generic;
using System.Text;

namespace rellotgeDigitalAmbAlarma
{
class Program
{
static void Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.BackgroundColor = ConsoleColor.Yellow;
Console.Clear();
int h, m, s, x;
int alarmaH, alarmaM, alarmaS;
String alarma;
Console.WriteLine("Introdueix les hores");
h = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Introdueix els minuts");
m = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Introdueix els segons");
s = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Vols possar alarma, si o no");
alarma = Convert.ToString(Console.ReadLine());


if (alarma == "si")
{
Console.Clear();
Console.WriteLine("Introdueix les hores de l'alarma");
alarmaH = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Introdueix els minuts de l'alarma");
alarmaM = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Introdueix els segons de l'alarma");
alarmaS = Convert.ToInt32(Console.ReadLine());

}
else
{
alarmaH = -1;
alarmaM = -1;
alarmaS = -1;
}


while (true)
{
Console.Clear();
Console.WriteLine("Son les {0}:{1}:{2}", h, m, s);
x = Environment.TickCount;
while (Environment.TickCount <= x + 1000) ;
s = s + 1;
if (alarmaH == h && alarmaM == m && alarmaS == s)
{
Console.Beep();
Console.Beep();
Console.Beep();

}


if (s == 60)
{
s = 0;
m = m + 1;
if (m == 60)
{
m = 0;
h = h + 1;
if (h == 24)
{
h = 0;

}
}
}
}

}

}
}

operaciones aritmeticas

/*
 * Created by SharpDevelop.
 * User: Hogar
 * Date: 02/10/2011
 * Time: 20:24
 *
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;

namespace nuevo
{
class If
{
    static void Main(string[] args)
    {
        int numero1,numero2;
        System.Console.Write("Ingrese el primer numero: ");
    numero1 = Int32.Parse(System.Console.ReadLine());

    System.Console.Write("Ingrese el segundo numero:");
    numero2 = Int32.Parse(System.Console.ReadLine());

    if( numero1 == numero2 )
        System.Console.WriteLine( numero1 + " == " + numero2);
    if( numero1 != numero2 )
        System.Console.WriteLine( numero1 + " != " + numero2);
    if( numero1 <numero2 )
        System.Console.WriteLine( numero1 + " <" + numero2);
    if( numero1> numero2 )
        System.Console.WriteLine( numero1 + "> " + numero2);
    if( numero1 <= numero2 )
        System.Console.WriteLine( numero1 + " <= " + numero2);
    if( numero1>= numero2 )
        System.Console.WriteLine( numero1 + ">= " + numero2);
}
}
}

Invertir una palabra

/*
 * Created by SharpDevelop.
 * User: Hogar
 * Date: 02/10/2011
 * Time: 20:24
 *
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;

namespace ivertir
{
class Programa
{
    static void Main(string[] args)
    {
        System.Console.Write("Ingrese una palabra: ");
        string palabra = System.Console.ReadLine();

        string invertida = invertir(palabra);

        if(palabra.Equals(invertida))
            System.Console.WriteLine("La palabra es Capicua");
        else
            System.Console.WriteLine("La palabra NO es Capicua");
    }

    private static string invertir(string cadena)
    {
        string invertido = "";

        for (int i = cadena.Length-1; i>= 0; i--)
            invertido = invertido + cadena.Substring(i, 1);

        return invertido;
    }
}
}

calcular la suma de dos numeros

using System;
using System.Collections.Generic;

namespace sma
{
class Suma
{
   static void Main(string[] args) {
       string   primerNumero, segundoNumero;
       int  numero1, numero2, suma;

       System.Console.Write("Ingrese el primer n├║mero: ");
       primerNumero = System.Console.ReadLine();

       System.Console.Write("Ingrese el segundo n├║mero: ");
       segundoNumero = System.Console.ReadLine();

       numero1 = Int16.Parse(primerNumero);
       numero2 = Int16.Parse(segundoNumero);
       suma = numero1 + numero2;

      Console.WriteLine("El resutado de la suma es {0}",suma);
   }
}
}

jueves, 29 de septiembre de 2011

calcular el promedio de los números a ingresar y saber cuales son mayores al promedio y menores al promedio

//Hacer una aplicación que forme un vector del que no se sabe el número
 //de elementos (el tamaño lo indica el usuario). Calcule el promedio
 //de todos los elementos y forme dos nuevos arreglos, uno con los
 //elementos menores o iguales al promedio y otro con los superiores.
 //Imprima los dos nuevos arreglos.

using System;

namespace Prog_Promedios
{
class Program
{
public static int lim;

public static void Main(string[] args)
{

Console.WriteLine("Determine el tamaño del Arreglo ");
lim=Convert.ToInt16(Console.ReadLine());

Console.Clear();
double[] num = new double [lim];

Console.WriteLine("Ingrese los valores ");
for(int t=0; t<lim; t++)
num[t]=Convert.ToDouble(Console.ReadLine());

Procesamiento(num);


Console.ReadKey(true);
}

public static void Procesamiento (double[] pv)
{
double p=0, pf=0;

for(int j=0; j<lim; j++)
p+=pv[j];
pf=p/lim;

Console.WriteLine("Promedio ==> {0}" , pf);

double[] m = new double [lim];
double[] n = new double [lim];


Console.WriteLine("Valores menores al promedio ");
for(int l=0; l<lim; l++){
if(pv[l]<=pf)
m[l]=pv[l];
Console.WriteLine("[{0}]" , m[l]);
}

Console.WriteLine("Valores mayores al promedio ");
for(int e=0; e<lim; e++){
if(pv[e]>=pf)
n[e]=pv[e];
Console.WriteLine("[{0}]" , n[e]);
}


}

}
}

producto de vectores inversamente

*
 * Creado por SharpDevelop.
 * Usuario: Administrador
 * Fecha: 30/07/2011
 * Hora: 6:14
 *
 * Para cambiar esta plantilla use Herramientas | Opciones | Codificación | Editar Encabezados Estándar
 */

//Elaborar una aplicación que lea dos arreglos unidimensionales de igual tamaño
//y forme un tercer arreglo mediante el producto de los elementos de los dos
//arreglos, tomados en orden inverso, es decir, productos del primer elemento
//del primer arreglo, con el último del segundo; del segundo del primer arreglo
//con el penúltimo del segundo arreglo; hasta llegara al último del primer
//arreglo, con el primero del segundo arreglo. Imprimir el arreglo formado.

using System;

namespace Produc_Arreglos_Inversos
{
class Program
{
public static void Main(string[] args)
{
int [] arreg1 = new int [5];
int [] arreg2 = new int [5];

Console.WriteLine("Llenando los arreglos . . ");
Console.WriteLine("Escriba 5 valores del primer arreglo ");
for(int m=0; m<5; m++)
arreg1[m]=Convert.ToInt16(Console.ReadLine());

Console.Clear();
Console.WriteLine("Llenando los arreglos . . ");
Console.WriteLine("Escriba 5 valores del segundo arreglo ");
for(int n=0; n<5; n++)
arreg2[n]=Convert.ToInt16(Console.ReadLine());

MetodoProceso(arreg1,arreg2);
Console.ReadKey(true);

}

public static void MetodoProceso (int[] a1, int[] a2)
{
int e=0;
int[] product = new int [5];

Console.SetCursorPosition(0,8);
Console.WriteLine("Elementos Vector 1");
for(int r=0; r<5; r++){
Console.Write("[{0}]",a1[r]);
}
Console.SetCursorPosition(0,11);
Console.WriteLine("Elementos Vector 2");
for(int t=0; t<5; t++){
Console.Write("[{0}]",a2[t]);
}

Console.SetCursorPosition(0,14);
Console.WriteLine("Producto de Vectores Inversamente ");
while(e<5){
for(int j=4; j>=0; j--){
product[e]=a1[e]*a2[j];
Console.Write("[{0}]",product[e]);
e++;
}
}
}

}
}