Skip to content

Instantly share code, notes, and snippets.

@albizures
Last active February 18, 2017 14:50
Show Gist options
  • Save albizures/5985d9ac6dd8b58f366b7d75b25f666c to your computer and use it in GitHub Desktop.
Save albizures/5985d9ac6dd8b58f366b7d75b25f666c to your computer and use it in GitHub Desktop.
umg
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Ingrese un numero");
int length = Convert.ToInt32(Console.ReadLine());
int longitud = 5;
int[,] MatrizIdentidad = new int[longitud, longitud];
for(int x = 0; x < longitud; x++)
{
for (int y = 0; y < longitud; y++ )
{
if (x == y)
{
Console.Write(" 1 ");
MatrizIdentidad[x,y] = 1;
}
else
{
Console.Write(" 0 ");
MatrizIdentidad[x,y] = 0;
}
}
Console.WriteLine("");
}
Console.WriteLine("");
String[][] jaggedArray = new String[3][];
jaggedArray[0] = new String [] {"a", "b"};
jaggedArray[1] = new String [] {"c", "d", "e", "f"};
jaggedArray[2] = new String [] {"g", "h", "i", "j", "k", "l"};
foreach (String[] x in jaggedArray)
{
foreach (String y in x)
{
Console.Write(" {0} ", y);
}
Console.WriteLine("");
}
Console.ReadLine();
}
}
}
using System;
using System.Text;
using System.IO;
class MainClass {
public static void Main (string[] args) {
MultiplicationTable FiveTable = new MultiplicationTable(5);
FiveTable.switchBy("while");
FiveTable.ifBy("while");
}
}
public class MultiplicationTable {
private int number;
public MultiplicationTable(int num) {
number = num;
}
public void byFor () {
Console.WriteLine ("Tabla hecha con un `for`\n");
for (int x = 1; x < 11; x++) {
this.printStep(x);
}
}
public void byWhile () {
Console.WriteLine ("Tabla hecha con un `while`\n");
int x = 1;
while (x < 11) {
this.printStep(x);
x++;
}
}
public void byDoWhile () {
Console.WriteLine ("Tabla hecha con un `do while`\n");
int x = 1;
do {
this.printStep(x);
x++;
} while (x < 10);
}
public void switchBy(string type) {
Console.WriteLine ("Tipo elegido con un `switch`");
switch (type) {
case "for":
this.byFor();
break;
case "doWhile":
this.byDoWhile();
break;
case "while":
this.byWhile();
break;
}
}
public void ifBy(string type) {
Console.WriteLine ("Tipo elegido con un `if's` y `else's`");
if (type == "for") {
this.byFor();
} else if (type == "doWhile") {
this.byDoWhile();
} else if (type == "while") {
this.byWhile();
}
}
private void printStep (int step) {
Console.WriteLine(number + "\tx\t" + step + "\t=\t" + this.getStep(step));
}
private int getStep (int step) {
return step * number;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment