Skip to content

Commit

Permalink
Merge pull request #104 from marcode24/2024-01-cs
Browse files Browse the repository at this point in the history
✨ Add csharp solution challenge-01
  • Loading branch information
marcode24 authored Sep 24, 2024
2 parents 41943b5 + a4006d0 commit 00deed6
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 1 deletion.
103 changes: 103 additions & 0 deletions 2024/01-operadores-y-estructuras-de-control/solution.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using System;

class OperadoresEstructurasControl
{
public static void Execute()
{
// Operadores aritméticos
int suma = 5 + 3;
int resta = 10 - 4;
int multiplicacion = 6 * 7;
double division = 20 / 4;
int modulo = 15 % 4;

Console.WriteLine("Operadores Aritméticos:");
Console.WriteLine($"Suma: {suma}");
Console.WriteLine($"Resta: {resta}");
Console.WriteLine($"Multiplicación: {multiplicacion}");
Console.WriteLine($"División: {division}");
Console.WriteLine($"Módulo: {modulo}");

// Operadores lógicos
bool and = true && false;
bool or = true || false;
bool not = !true;

Console.WriteLine("\nOperadores Lógicos:");
Console.WriteLine($"AND: {and}");
Console.WriteLine($"OR: {or}");
Console.WriteLine($"NOT: {not}");

// Operadores de comparación
bool igual = 5 == int.Parse("5"); // Conversión necesaria en C#
bool diferente = 10 != 5;
bool mayorQue = 15 > 10;
bool menorQue = 7 < 12;

Console.WriteLine("\nOperadores de Comparación:");
Console.WriteLine($"Igual (==): {igual}");
Console.WriteLine($"Diferente (!=): {diferente}");
Console.WriteLine($"Mayor Que (>): {mayorQue}");
Console.WriteLine($"Menor Que (<): {menorQue}");

// Operadores de asignación
int x = 10;
x += 5; // equivalente a x = x + 5
int y = 20;
y *= 2; // equivalente a y = y * 2

Console.WriteLine("\nOperadores de Asignación:");
Console.WriteLine($"x: {x}");
Console.WriteLine($"y: {y}");

// Operadores bitwise
int bitwiseAnd = 5 & 3; // AND
int bitwiseOr = 5 | 3; // OR
int bitwiseXor = 5 ^ 3; // XOR
int bitwiseNot = ~5; // NOT
int leftShift = 5 << 1; // Left Shift
int rightShift = 5 >> 1; // Right Shift
int zeroFillRightShift = (int)((uint)5 >> 1); // Zero-fill Right Shift

Console.WriteLine("\nOperadores Bitwise:");
Console.WriteLine($"Bitwise AND (&): {bitwiseAnd}");
Console.WriteLine($"Bitwise OR (|): {bitwiseOr}");
Console.WriteLine($"Bitwise XOR (^): {bitwiseXor}");
Console.WriteLine($"Bitwise NOT (~): {bitwiseNot}");
Console.WriteLine($"Left Shift (<<): {leftShift}");
Console.WriteLine($"Right Shift (>>): {rightShift}");
Console.WriteLine($"Zero-fill Right Shift (>>>): {zeroFillRightShift}");

// Estructuras de control
// Condicionales
int edad = 18;
if (edad >= 18)
{
Console.WriteLine("\nEres mayor de edad.");
}
else
{
Console.WriteLine("\nEres menor de edad.");
}

// Iterativas
Console.WriteLine("\nNúmeros entre 10 y 55 (pares, no 16 ni múltiplos de 3):");
for (int i = 10; i <= 55; i++)
{
if (i % 2 == 0 && i != 16 && i % 3 != 0)
{
Console.WriteLine(i);
}
}

// Excepciones
try
{
throw new Exception("Este es un ejemplo de excepción.");
}
catch (Exception ex)
{
Console.WriteLine($"\nExcepción: {ex.Message}");
}
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ dotnet run 2024 00
| # | Challenge | Difficulty | My Solution |
| :-: | ------------------------------------------------------------------------------------------- | :--------: | --------------------------------------------------------------------------------------------------------------------- |
| 00 | [Sintaxis, Variables, Tipos de datos y Hola Mundo](https://retosdeprogramacion.com/roadmap/)| 🟢 | [![JavaScript](https://img.shields.io/badge/-JavaScript-F7DF1E?style=flat&logo=javascript&logoColor=black)](./2024/00-sintaxis-variables-tipos-de-datos-y-hola-mundo/index.js) <br /> [![TypeScript](https://img.shields.io/badge/-TypeScript-3178C6?style=flat&logo=typescript&logoColor=white)](./2024/00-sintaxis-variables-tipos-de-datos-y-hola-mundo/solution.ts) <br /> [![PHP](https://img.shields.io/badge/PHP-777BB4?style=flat&logo=php&logoColor=white)](./2024/00-sintaxis-variables-tipos-de-datos-y-hola-mundo/solution.php) <br /> [![C#](https://img.shields.io/badge/C%23-239120?style=flat&logo=c-sharp&logoColor=white)](./2024/00-sintaxis-variables-tipos-de-datos-y-hola-mundo/solution.cs) |
| 01 | [Operadores y Estructuras de Control](https://retosdeprogramacion.com/roadmap/) | 🟢 | [![JavaScript](https://img.shields.io/badge/-JavaScript-F7DF1E?style=flat&logo=javascript&logoColor=black)](./2024/01-operadores-y-estructuras-de-control/index.js) <br /> [![TypeScript](https://img.shields.io/badge/-TypeScript-3178C6?style=flat&logo=typescript&logoColor=white)](./2024/01-operadores-y-estructuras-de-control/solution.ts) <br /> [![PHP](https://img.shields.io/badge/PHP-777BB4?style=flat&logo=php&logoColor=white)](./2024/01-operadores-y-estructuras-de-control/solution.php) |
| 01 | [Operadores y Estructuras de Control](https://retosdeprogramacion.com/roadmap/) | 🟢 | [![JavaScript](https://img.shields.io/badge/-JavaScript-F7DF1E?style=flat&logo=javascript&logoColor=black)](./2024/01-operadores-y-estructuras-de-control/index.js) <br /> [![TypeScript](https://img.shields.io/badge/-TypeScript-3178C6?style=flat&logo=typescript&logoColor=white)](./2024/01-operadores-y-estructuras-de-control/solution.ts) <br /> [![PHP](https://img.shields.io/badge/PHP-777BB4?style=flat&logo=php&logoColor=white)](./2024/01-operadores-y-estructuras-de-control/solution.php) <br /> [![C#](https://img.shields.io/badge/C%23-239120?style=flat&logo=c-sharp&logoColor=white)](./2024/01-operadores-y-estructuras-de-control/solution.cs) |
| 02 | [Funciones y alcance](https://retosdeprogramacion.com/roadmap/) | 🟢 | [![JavaScript](https://img.shields.io/badge/-JavaScript-F7DF1E?style=flat&logo=javascript&logoColor=black)](./2024/02-funciones-y-alcance/index.js) <br /> [![TypeScript](https://img.shields.io/badge/-TypeScript-3178C6?style=flat&logo=typescript&logoColor=white)](./2024/02-funciones-y-alcance/solution.ts) <br /> [![PHP](https://img.shields.io/badge/PHP-777BB4?style=flat&logo=php&logoColor=white)](./2024/02-funciones-y-alcance/solution.php) |
| 03 | [Estructuras de Datos](https://retosdeprogramacion.com/roadmap/) | 🟡 | [![JavaScript](https://img.shields.io/badge/-JavaScript-F7DF1E?style=flat&logo=javascript&logoColor=black)](./2024/03-estructuras-de-datos/index.js) <br /> [![TypeScript](https://img.shields.io/badge/-TypeScript-3178C6?style=flat&logo=typescript&logoColor=white)](./2024/03-estructuras-de-datos/solution.ts) <br /> [![PHP](https://img.shields.io/badge/PHP-777BB4?style=flat&logo=php&logoColor=white)](./2024/03-estructuras-de-datos/solution.php) |
| 04 | [Cadena de Caracteres](https://retosdeprogramacion.com/roadmap/) | 🟡 | [![JavaScript](https://img.shields.io/badge/-JavaScript-F7DF1E?style=flat&logo=javascript&logoColor=black)](./2024/04-cadenas-de-caracteres/index.js) <br /> [![TypeScript](https://img.shields.io/badge/-TypeScript-3178C6?style=flat&logo=typescript&logoColor=white)](./2024/04-cadenas-de-caracteres/solution.ts) <br /> [![PHP](https://img.shields.io/badge/PHP-777BB4?style=flat&logo=php&logoColor=white)](./2024/04-cadenas-de-caracteres/solution.php) |
Expand Down
1 change: 1 addition & 0 deletions weekly-challenges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ private class Challenge(string name, Action execute)

private static readonly Dictionary<string, Challenge> challenges2024 = new() {
{ "00", new Challenge("Sintaxis, variables, tipos de datos y ¡Hola, Mundo!", SintaxisVariables.Execute) },
{ "01", new Challenge("Operadores y estructuras de control", OperadoresEstructurasControl.Execute) },
};

private static readonly Dictionary<int, Dictionary<string, Challenge>> challengeActions = new() {
Expand Down

0 comments on commit 00deed6

Please sign in to comment.