Skip to content

Commit 00deed6

Browse files
authored
Merge pull request #104 from marcode24/2024-01-cs
✨ Add csharp solution challenge-01
2 parents 41943b5 + a4006d0 commit 00deed6

File tree

3 files changed

+105
-1
lines changed

3 files changed

+105
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using System;
2+
3+
class OperadoresEstructurasControl
4+
{
5+
public static void Execute()
6+
{
7+
// Operadores aritméticos
8+
int suma = 5 + 3;
9+
int resta = 10 - 4;
10+
int multiplicacion = 6 * 7;
11+
double division = 20 / 4;
12+
int modulo = 15 % 4;
13+
14+
Console.WriteLine("Operadores Aritméticos:");
15+
Console.WriteLine($"Suma: {suma}");
16+
Console.WriteLine($"Resta: {resta}");
17+
Console.WriteLine($"Multiplicación: {multiplicacion}");
18+
Console.WriteLine($"División: {division}");
19+
Console.WriteLine($"Módulo: {modulo}");
20+
21+
// Operadores lógicos
22+
bool and = true && false;
23+
bool or = true || false;
24+
bool not = !true;
25+
26+
Console.WriteLine("\nOperadores Lógicos:");
27+
Console.WriteLine($"AND: {and}");
28+
Console.WriteLine($"OR: {or}");
29+
Console.WriteLine($"NOT: {not}");
30+
31+
// Operadores de comparación
32+
bool igual = 5 == int.Parse("5"); // Conversión necesaria en C#
33+
bool diferente = 10 != 5;
34+
bool mayorQue = 15 > 10;
35+
bool menorQue = 7 < 12;
36+
37+
Console.WriteLine("\nOperadores de Comparación:");
38+
Console.WriteLine($"Igual (==): {igual}");
39+
Console.WriteLine($"Diferente (!=): {diferente}");
40+
Console.WriteLine($"Mayor Que (>): {mayorQue}");
41+
Console.WriteLine($"Menor Que (<): {menorQue}");
42+
43+
// Operadores de asignación
44+
int x = 10;
45+
x += 5; // equivalente a x = x + 5
46+
int y = 20;
47+
y *= 2; // equivalente a y = y * 2
48+
49+
Console.WriteLine("\nOperadores de Asignación:");
50+
Console.WriteLine($"x: {x}");
51+
Console.WriteLine($"y: {y}");
52+
53+
// Operadores bitwise
54+
int bitwiseAnd = 5 & 3; // AND
55+
int bitwiseOr = 5 | 3; // OR
56+
int bitwiseXor = 5 ^ 3; // XOR
57+
int bitwiseNot = ~5; // NOT
58+
int leftShift = 5 << 1; // Left Shift
59+
int rightShift = 5 >> 1; // Right Shift
60+
int zeroFillRightShift = (int)((uint)5 >> 1); // Zero-fill Right Shift
61+
62+
Console.WriteLine("\nOperadores Bitwise:");
63+
Console.WriteLine($"Bitwise AND (&): {bitwiseAnd}");
64+
Console.WriteLine($"Bitwise OR (|): {bitwiseOr}");
65+
Console.WriteLine($"Bitwise XOR (^): {bitwiseXor}");
66+
Console.WriteLine($"Bitwise NOT (~): {bitwiseNot}");
67+
Console.WriteLine($"Left Shift (<<): {leftShift}");
68+
Console.WriteLine($"Right Shift (>>): {rightShift}");
69+
Console.WriteLine($"Zero-fill Right Shift (>>>): {zeroFillRightShift}");
70+
71+
// Estructuras de control
72+
// Condicionales
73+
int edad = 18;
74+
if (edad >= 18)
75+
{
76+
Console.WriteLine("\nEres mayor de edad.");
77+
}
78+
else
79+
{
80+
Console.WriteLine("\nEres menor de edad.");
81+
}
82+
83+
// Iterativas
84+
Console.WriteLine("\nNúmeros entre 10 y 55 (pares, no 16 ni múltiplos de 3):");
85+
for (int i = 10; i <= 55; i++)
86+
{
87+
if (i % 2 == 0 && i != 16 && i % 3 != 0)
88+
{
89+
Console.WriteLine(i);
90+
}
91+
}
92+
93+
// Excepciones
94+
try
95+
{
96+
throw new Exception("Este es un ejemplo de excepción.");
97+
}
98+
catch (Exception ex)
99+
{
100+
Console.WriteLine($"\nExcepción: {ex.Message}");
101+
}
102+
}
103+
}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ dotnet run 2024 00
7070
| # | Challenge | Difficulty | My Solution |
7171
| :-: | ------------------------------------------------------------------------------------------- | :--------: | --------------------------------------------------------------------------------------------------------------------- |
7272
| 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) |
73-
| 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) |
73+
| 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) |
7474
| 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) |
7575
| 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) |
7676
| 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) |

weekly-challenges.cs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ private class Challenge(string name, Action execute)
1010

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

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

0 commit comments

Comments
 (0)