Skip to content

Commit c952460

Browse files
authored
Merge pull request #8952 from isco-mtz/main
reto00
2 parents 7aedfa5 + 4578b4c commit c952460

File tree

2 files changed

+244
-0
lines changed
  • Roadmap
    • 00 - SINTAXIS, VARIABLES, TIPOS DE DATOS Y HOLA MUNDO/c#
    • 01 - OPERADORES Y ESTRUCTURAS DE CONTROL/c#

2 files changed

+244
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
namespace retoProgramacion2025
3+
{
4+
internal class reto00
5+
{
6+
static void Main(string[] args)
7+
{
8+
// https://learn.microsoft.com/es-es/dotnet/csharp/tour-of-csharp/overview
9+
// Comentario de una linea
10+
11+
/* Comentario de
12+
* varias
13+
* lineas
14+
*/
15+
16+
//Crear variable y constante
17+
int entero = 1;
18+
const int constanteEntero = 2;
19+
20+
// Tipos primitivos
21+
sbyte mySbyte = 1;
22+
Console.WriteLine(mySbyte);
23+
byte myByte = 1;
24+
Console.WriteLine(myByte);
25+
short myShort = 1;
26+
Console.WriteLine(myShort);
27+
ushort myUShort = 1;
28+
Console.WriteLine(myUShort);
29+
int myInt = 1;
30+
Console.WriteLine(myInt);
31+
uint myUInt = 1;
32+
Console.WriteLine(myUInt);
33+
long myLong = 1;
34+
Console.WriteLine(myLong);
35+
ulong myULong = 1;
36+
Console.WriteLine(myULong);
37+
float myFloat = 5.9998f;
38+
Console.WriteLine(myFloat);
39+
double myDouble = 5.99;
40+
Console.WriteLine(myDouble);
41+
decimal myDecimal = 10.0m;
42+
Console.WriteLine(myDecimal);
43+
char myChar = 'A';
44+
Console.WriteLine(myChar);
45+
bool myBoolean = false;
46+
Console.WriteLine(myBoolean);
47+
Console.WriteLine("");
48+
Console.WriteLine("¡Hola, C#!");
49+
}
50+
}
51+
}
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
2+
using System;
3+
4+
namespace retoProgramacion2025
5+
{
6+
7+
internal class reto01
8+
{
9+
// Variable global
10+
static int globalVariable = 70;
11+
12+
private static void Main(string[] args)
13+
{
14+
MostrarOperadoresAritmeticos();
15+
MostrarOperadoresLogicos();
16+
MostrarOperadoresComparacion();
17+
MostrarOperadoresAsignacion();
18+
MostrarOperadoresIdentidad();
19+
MostrarEstructurasControl();
20+
21+
Console.WriteLine("\nEjercicio Extra:");
22+
ImprimirNumeros();
23+
}
24+
25+
// Operadores aritméticos
26+
static void MostrarOperadoresAritmeticos()
27+
{
28+
Console.WriteLine("Operadores aritméticos: ");
29+
30+
int a = 5;
31+
int b = 2;
32+
33+
Console.WriteLine($"a + b = {a + b}");
34+
Console.WriteLine($"a - b = {a - b}");
35+
Console.WriteLine($"a * b = {a * b}");
36+
Console.WriteLine($"a / b = {(double)a / b}");
37+
Console.WriteLine($"a % b = {a % b}");
38+
}
39+
40+
// Operadores lógicos
41+
static void MostrarOperadoresLogicos()
42+
{
43+
Console.WriteLine("\nOperadores lógicos: ");
44+
45+
bool x = true;
46+
bool y = false;
47+
48+
Console.WriteLine($"El valor de x es: {x}");
49+
Console.WriteLine($"El valor de y es: {y}");
50+
Console.WriteLine("\n");
51+
52+
Console.WriteLine($"x && y = {x && y}");
53+
Console.WriteLine($"x || y = {x || y}");
54+
Console.WriteLine($"!x = {!x}");
55+
}
56+
57+
// Operadores de comparación
58+
static void MostrarOperadoresComparacion()
59+
{
60+
Console.WriteLine("\nOperadores de comparación: ");
61+
62+
int a = 10;
63+
int b = 10;
64+
65+
Console.WriteLine($"a == b = {a == b}");
66+
Console.WriteLine($"a != b = {a != b}");
67+
Console.WriteLine($"a > b = {a > b}");
68+
Console.WriteLine($"a < b = {a < b}");
69+
Console.WriteLine($"a >= b = {a >= b}");
70+
Console.WriteLine($"a <= b = {a <= b}");
71+
}
72+
73+
// Operadores de asignación
74+
static void MostrarOperadoresAsignacion()
75+
{
76+
Console.WriteLine("\nOperadores de asignación: ");
77+
78+
int c = 125;
79+
Console.WriteLine($"c = {c}");
80+
81+
c += 10;
82+
Console.WriteLine($"c += 10 = {c}");
83+
84+
c -= 20;
85+
Console.WriteLine($"c -= 20 = {c}");
86+
87+
c *= 30;
88+
Console.WriteLine($"c *= 30 = {c}");
89+
90+
c /= 50;
91+
Console.WriteLine($"c /= 50 = {c}");
92+
93+
c %= 60;
94+
Console.WriteLine($"c %= 60 = {c}");
95+
}
96+
97+
// Identidad / referencia
98+
static void MostrarOperadoresIdentidad()
99+
{
100+
Console.WriteLine("\nOperadores de identidad: ");
101+
102+
string a1 = "Arroz";
103+
string a2 = "Galletas";
104+
105+
Console.WriteLine($"El valor de a1 es: {a1}");
106+
Console.WriteLine($"El valor de a2 es: {a2}");
107+
Console.WriteLine($"a1 == a2 = {a1 == a2}");
108+
Console.WriteLine($"ReferenceEquals(a1, a2) = {ReferenceEquals(a1, a2)}");
109+
}
110+
111+
// Estructuras de control
112+
static void MostrarEstructurasControl()
113+
{
114+
Console.WriteLine("\nEstructuras de control: ");
115+
116+
int a = 45;
117+
int b = 7;
118+
119+
// IF
120+
if (a > b)
121+
Console.WriteLine("a es mayor que b");
122+
else
123+
Console.WriteLine("a no es mayor que b");
124+
125+
// SWITCH
126+
switch (a)
127+
{
128+
case 35:
129+
Console.WriteLine("a es 35");
130+
break;
131+
case 7:
132+
Console.WriteLine("a es 7");
133+
break;
134+
default:
135+
Console.WriteLine($"a no es 35, su valor es: {a}");
136+
break;
137+
}
138+
139+
// FOR
140+
Console.WriteLine("\nFor:");
141+
for (int i = 0; i < 5; i++)
142+
Console.WriteLine(i);
143+
144+
// WHILE
145+
Console.WriteLine("\nWhile:");
146+
int j = 0;
147+
while (j < 5)
148+
Console.WriteLine(j++);
149+
150+
// DO-WHILE
151+
Console.WriteLine("\nDo-While:");
152+
int k = 0;
153+
do
154+
{
155+
Console.WriteLine(k++);
156+
} while (k < 5);
157+
158+
// FOREACH
159+
Console.WriteLine("\nForeach:");
160+
int[] numeros = { 1, 2, 3, 4, 5, 6, 7 };
161+
foreach (int num in numeros)
162+
Console.WriteLine($"ForEach número: {num}");
163+
164+
// Excepciones
165+
Console.WriteLine("\nExcepciones:");
166+
167+
try
168+
{
169+
int x = 3;
170+
int y = 0;
171+
Console.WriteLine(x / y);
172+
}
173+
catch (Exception e)
174+
{
175+
Console.WriteLine("Error: " + e.Message);
176+
}
177+
finally
178+
{
179+
Console.WriteLine("Finally ejecutado");
180+
}
181+
}
182+
183+
// Ejercicio extra: números pares entre 10 y 55, sin 16 ni múltiplos de 3
184+
static void ImprimirNumeros()
185+
{
186+
for (int i = 10; i <= 55; i++)
187+
{
188+
if (i % 2 == 0 && i != 16 && i % 3 != 0)
189+
Console.WriteLine(i);
190+
}
191+
}
192+
}
193+
}

0 commit comments

Comments
 (0)