You are on page 1of 19

C:\Users\ferna\Documents\Programa c\2NDA TAREA\Prog1.

cs 1
1 using System;
2
3 namespace _2NDA_TAREA
4 {
5 class programa1
6 {
7 static void Main(string[] args)
8 {
9 int num, i = 3, count, c, factor = 2;
10
11 Console.WriteLine("Digite la cantidad de numeros primos: ");
12 num = Convert.ToInt32(Console.ReadLine());
13
14 if (num >= 1)
15 {
16
17 Console.WriteLine("Los primos hasta " + num + "son:\n");
18 Console.WriteLine("2");
19 }
20
21
22 for (count = 2; count <= num;)
23 {
24 for (c = 2; c <= i - 1; c++)
25 {
26 if (i % c == 0)
27 break;
28 }
29 if (c == i)
30 {
31 PrimeFactors(i);
32 Console.WriteLine("\n" + i);
33 count++;
34 }
35 i++;
36
37 }
38 }
39 public static void PrimeFactors(int n)
40 {
41 while (n % 2 == 0)
42 {
43 Console.Write(2 + " ");
44 n /= 2;
45 }
46 }
47 }
48
49
50
51 }
52
53
C:\Users\ferna\Documents\Programa c\2NDA TAREA\Prog2.cs 1
1 using System;
2
3 namespace _2NDA_TAREA
4 {
5 class programa2
6 {
7 static void Main(string[] args)
8 {
9 String f = "";
10 Console.WriteLine("Digite la frase: ");
11 String frase = Console.ReadLine();
12
13 for (int x = frase.Length - 1; x >= 0; x--)
14 {
15
16 f += frase[x];
17 }
18 Console.WriteLine("Su frase invertida es: " + f);
19 }
20
21
22
23 }
24
25
26
27 }
28
29
C:\Users\ferna\Documents\Programa c\2NDA TAREA\Prog3.cs 1
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6
7 namespace _2NDA_TAREA
8 {
9 class Prog3
10 {
11 static void Main(string[] args)
12 {
13
14 int aa = 0, bb = 0, cc = 0, cc1 = 1, rr = 1, v1 = 1, ml =
1, v2 = 3, rr1 = 1, ax = 5;
15
16 int[,] M = new int[5, 5];
17
18 for (int f = 0; f < 5; f++)
19 {
20 for (int c = 0; c < 5; c++)
21 {
22 if (c == 0)
23 {
24 if (f == 0)
25 {
26 M[f, c] = aa;
27 }
28 else
29 {
30 rr = v1 * v1;
31 M[f, c] = rr;
32 v1++;
33 rr = 1;
34 }
35 }
36
37 if (c == 1)
38 {
39 if (f == 0)
40 {
41 M[f, c] = aa;
42 }
43 else
44 {
45 M[f, c] = cc1++;
46 }
47 }
48 if (cc == 2)
49 {
50
51 if (f == 0)
52 {
C:\Users\ferna\Documents\Programa c\2NDA TAREA\Prog3.cs 2
53 M[f, c] = aa;
54 }
55 else
56 {
57 ml = v2 * v2;
58 M[f, c] = ml;
59 v2++;
60 ml = 1;
61 }
62
63 }
64
65 if (c == 3)
66 {
67 if (f == 0)
68 {
69 M[f, c] = aa;
70 }
71 else
72 {
73 bb = bb + 3;
74 M[f, c] = bb;
75 }
76 }
77
78 if (c == 4)
79 {
80 if (f == 0)
81 {
82 M[f, c] = aa;
83
84 }
85 else
86 {
87 rr1 = ax * ax;
88 M[f, c] = rr1;
89 ax = ax + 1;
90 rr = 1;
91 }
92 }
93 }
94 }
95 for (int f = 0; f < 5; f++)
96 {
97 for (int c = 0; c < 5; c++)
98 {
99 Console.Write(M[c, f] + " ");
100 }
101 Console.WriteLine("");
102 }
103 Console.ReadKey();
104 }
105 }
C:\Users\ferna\Documents\Programa c\2NDA TAREA\Prog3.cs 3
106 }
107
C:\Users\ferna\Documents\Programa c\2NDA TAREA\Prog4.cs 1
1 using System;
2
3 namespace _2NDA_TAREA
4 {
5 class programa4
6 {
7 static void Main(string[] args)
8 {
9 //int a = 0, b = -1, c1 = 2, d = -3, e = 4;
10 int AX = 0, BX = -1, CX = 2, DX = -3, EX = 4;
11
12 int[,] M = new int[5, 5];
13
14 for (int f = 0; f < 5; f++)
15 {
16 for (int c = 0; c < 5; c++)
17 {
18 if (f == 0)
19 {
20 M[f, c] = AX++;
21 }
22
23 if (f == 1)
24 {
25 M[f, c] = BX++;
26 }
27
28 if (f == 2)
29 {
30 M[f, c] = CX++;
31 }
32
33 if (f == 3)
34 {
35 M[f, c] = DX++;
36 }
37
38 if (f == 4)
39 {
40 M[f, c] = EX++;
41 }
42 }
43 }
44
45 for (int f = 0; f < 5; f++)
46 {
47 for (int c = 0; c < 5; c++)
48 {
49 Console.Write(" " + M[c, f] + " ");
50 }
51
52 Console.WriteLine("");
53
C:\Users\ferna\Documents\Programa c\2NDA TAREA\Prog4.cs 2
54
55 }
56
57 Console.ReadKey();
58 }
59 }
60
61
62
63 }
64
65
66
67
68
69
70
C:\Users\ferna\Documents\Programa c\2NDA TAREA\Prog5.cs 1
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6
7 namespace _2NDA_TAREA
8 {
9 class Prog5
10 {
11 static void Main(string[] args)
12 {
13 int can, sumapares = 0, sumaimpares = 0;
14 String num;
15
16
17
18 int[] arreglo = new int[10];
19
20 Console.WriteLine("Cuantos elementos tendra el arreglo: ");
21 can = int.Parse(Console.ReadLine());
22
23 for (int i = 1; i <= can; i++)
24 {
25 Console.WriteLine("Posicion" + i + "-->");
26 num = Console.ReadLine();
27 arreglo[i] = int.Parse(num);
28 }
29
30 for(int i = 1; i<=can; i++)
31 {
32 if ((arreglo[i]%2)==0)
33 {
34 sumapares = sumapares + arreglo[i];
35
36 }
37 else
38 {
39 sumaimpares = sumaimpares + arreglo[i];
40
41 }
42
43 }
44 Console.WriteLine();
45 Console.WriteLine("Suma de pares: "+sumapares);
46 Console.WriteLine("Suma de impares: "+ sumaimpares);
47 Console.WriteLine();
48
49
50
51 }
52
53
C:\Users\ferna\Documents\Programa c\2NDA TAREA\Prog5.cs 2
54
55
56
57
58
59
60
61
62
63
64
65
66 }
67 }
68
69
C:\Users\ferna\Documents\Programa c\2NDA TAREA\Prog6.cs 1
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6
7 namespace _2NDA_TAREA
8 {
9 class Prog6
10 {
11 static void Main(string[] args)
12 {
13 int i = 0, can = 0;
14 String cad = "5";
15 can = int.Parse(cad);
16
17 int[]arr1 = new int[can + 1];
18 int[]arr2 = new int[can + 1];
19 int[] suma = new int[can + 1];
20
21 Console.WriteLine("Arreglo 1");
22 for (i = 1; i <= can; i++)
23 {
24 Console.WriteLine("Posicion {0}--> ", i);
25 cad = Console.ReadLine();
26 arr1[i] = int.Parse(cad);
27 }
28
29 Console.WriteLine("Arreglo 2");
30 for (i = 1; i <= can; i++)
31 {
32 Console.WriteLine("Posicion {0}--> ", i);
33 cad = Console.ReadLine();
34 arr2[i] = int.Parse(cad);
35 }
36
37 for(i = 1; i <= can; i++)
38 {
39 suma[i] = arr1[i] + arr2[i];
40
41 }
42
43 Console.WriteLine("La suma de vectores");
44 for (i = 1; i <= can; i++) {
45 Console.WriteLine("Posicion {0}--> ", i);
46 Console.WriteLine(suma[i]);
47
48 }
49 Console.ReadKey();
50 }
51 }
52 }
53
C:\Users\ferna\Documents\Programa c\2NDA TAREA\Prog7.cs 1
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6
7 namespace _2NDA_TAREA
8 {
9 class Prog7
10 {
11 static void Main(string[] args)
12 {
13 String emp1, emp2, emp3, emp4, emp5, em;
14 int s1, s2, s3, s4, s5, sm;
15
16 Console.WriteLine("Ingrese el nombre del empleado 1: ");
17 emp1 = Console.ReadLine();
18 Console.WriteLine("Ingrese el sueldo del empleado 1: ");
19 s1 = int.Parse(Console.ReadLine());
20
21 Console.WriteLine("Ingrese el nombre del empleado 2: ");
22 emp2 = Console.ReadLine();
23 Console.WriteLine("Ingrese el sueldo del empleado 2: ");
24 s2 = int.Parse(Console.ReadLine());
25
26 Console.WriteLine("Ingrese el nombre del empleado 3: ");
27 emp3 = Console.ReadLine();
28 Console.WriteLine("Ingrese el sueldo del empleado 3: ");
29 s3 = int.Parse(Console.ReadLine());
30
31 Console.WriteLine("Ingrese el nombre del empleado 4: ");
32 emp4 = Console.ReadLine();
33 Console.WriteLine("Ingrese el sueldo del empleado 4: ");
34 s4 = int.Parse(Console.ReadLine());
35
36 Console.WriteLine("Ingrese el nombre del empleado 5: ");
37 emp5 = Console.ReadLine();
38 Console.WriteLine("Ingrese el sueldo del empleado 5: ");
39 s5 = int.Parse(Console.ReadLine());
40
41 if (s1 > s2)
42 {
43 sm = s1;
44 em = emp1;
45 }
46 else
47 {
48 sm = s2;
49 em = emp2;
50 }
51
52 if (s2 > s3)
53 {
C:\Users\ferna\Documents\Programa c\2NDA TAREA\Prog7.cs 2
54 sm = s2;
55 em = emp2;
56
57
58 }
59 else
60 {
61 sm = s3;
62 em = emp3;
63 }
64
65 if (s3 > s4)
66 {
67 sm = s3;
68 em = emp3;
69
70 }
71 else
72 {
73 sm = s4;
74 em = emp4;
75
76 }
77
78 if (s4 > s5)
79 {
80 sm = s4;
81 em = emp4;
82 }
83 else
84 {
85 sm = s5;
86 em = emp5;
87 }
88
89 Console.WriteLine("El sueldo mayor es: " + sm + " del
emplead@ " + em); ;
90 }
91
92 }
93 }
94
95
C:\Users\ferna\Documents\Programa c\2NDA TAREA\Prog8.cs 1
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6
7 namespace _2NDA_TAREA
8 {
9 class Prog8
10 {
11 static void Main(string[] args)
12 {
13 int can, aux;
14 String num;
15
16 Console.WriteLine("Cuantos elementos tendra el arreglo: ");
17 can = int.Parse(Console.ReadLine());
18
19 int[] arreglo = new int[can];
20
21 for (int i = 0; i < can; i++) {
22 Console.WriteLine("Digite un numero: ");
23 num = Console.ReadLine();
24 arreglo[i] = int.Parse(num);
25 }
26
27 for (int i = 0; i < (can-1); i++)
28 {
29 for(int j=0; j < (can - 1); j++)
30 {
31 if (arreglo[j] > arreglo[j+1])
32 {
33 aux = arreglo[j];
34 arreglo[j] = arreglo[j + 1];
35 arreglo[j + 1] = aux;
36 }
37
38 }
39
40 }
41 Console.WriteLine("Arreglo ordenado en forma creciente");
42 for (int i = 0; i < can; i++) {
43 Console.WriteLine(arreglo[i]+" - ");
44 }
45
46 Console.WriteLine("Arreglo ordenado en forma creciente");
47 for (int i = (can-1); i >= 0; i--)
48 {
49 Console.WriteLine(arreglo[i] + " - ");
50 }
51
52
53 }
C:\Users\ferna\Documents\Programa c\2NDA TAREA\Prog8.cs 2
54 }
55 }
56
C:\Users\ferna\Documents\Programa c\2NDA TAREA\Prog9.cs 1
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6
7 namespace _2NDA_TAREA
8 {
9 class Prog9
10 {
11
12
13 static void Main(string[] args)
14 {
15 Random aleatorio = new Random();
16 int[,] matriz = new int[5, 5];
17
18 for (int i = 0; i < matriz.GetLength(0); i++)
19 {
20 for (int j = 0; j < matriz.GetLength(1); j++)
21 {
22 matriz[i, j] = aleatorio.Next(0, 100);
23
24 }
25 }
26 for (int i = 0; i < matriz.GetLength(0); i++)
27 {
28 for (int j = 0; j < matriz.GetLength(1); j++)
29 {
30 Console.Write(matriz[i, j] + "\t");
31 }
32 Console.WriteLine();
33 }
34
35 int[] diagonalPrincipal = new int[matriz.GetLength(0)];
36 int[] diagonalSecundaria = new int[matriz.GetLength(0)];
37 for (int i = 0; i < matriz.GetLength(0); i++)
38 {
39 for (int j = 0; j < matriz.GetLength(1); j++)
40 {
41 if (i == j)
42 {
43 diagonalPrincipal[i] = matriz[i, j];
44 }
45 if ((i + j) == (matriz.GetLength(0) - 1))
46 {
47 diagonalSecundaria[i] = matriz[i, j];
48 }
49 }
50 }
51 Console.WriteLine();
52 int suma = 0;
53 int multiplicacion = 1;
C:\Users\ferna\Documents\Programa c\2NDA TAREA\Prog9.cs 2
54 foreach (int numero in diagonalPrincipal)
55 {
56 Console.Write(numero + "\t");
57 suma = suma + numero;
58 }
59 Console.WriteLine("suma diagonal principal=" + suma + "\n");
60 suma = 0;
61 foreach (int numero in diagonalSecundaria)
62 {
63 Console.Write(numero + "\t");
64 multiplicacion = multiplicacion * numero;
65 }
66 Console.WriteLine("Multiplicacion diagonal secundaria=" +
multiplicacion + "\n");
67 Console.Read();
68
69 }
70
71 }
72
73 }
74
C:\Users\ferna\Documents\Programa c\2NDA TAREA\Prog10.cs 1
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6
7 namespace _2NDA_TAREA
8 {
9 class Prog10
10 {
11 static void Main(string[] args)
12 {
13 int[,] M = new int[5, 5];
14 Random aleatorio = new Random();
15 int temp;
16
17 for (int i = 0; i < M.GetLength(0); i++)
18 {
19 for (int j = 0; j < M.GetLength(1); j++)
20 {
21 M[i, j] = aleatorio.Next(0, 100);
22 }
23 }
24
25 for (int i = 0; i < M.GetLength(0); i++)
26 {
27 for (int j = 0; j < M.GetLength(1); j++)
28 {
29
30 Console.Write(M[i, j] + "\t");
31 }
32 Console.WriteLine();
33 }
34
35
36
37 }
38 }
39 }
40
C:\Users\ferna\Documents\Programa c\2NDA TAREA\Prog11.cs 1
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6
7 namespace _2NDA_TAREA
8 {
9 internal class Prog11
10 {
11 static void Main(string[] args)
12 {
13
14 int[,] M = new int[5, 5];
15
16 int AX = 1, BX = 2, CX = 4, DX = 1, EX = 6, FX = 7, GX=4;
17
18 for (int fila = 0; fila < 5; fila++) {
19 for (int columna = 0; columna < 5; columna++)
20 {
21 if(columna == 0)
22 {
23 M[fila, columna] = AX++;
24 }
25 else if(fila == 0)
26 {
27 M[fila, columna] = BX++;
28
29 }
30 else if(fila == 4)
31 {
32 M[fila, columna] = CX--;
33
34 }
35 else if(columna == 1)
36 {
37 M[fila, columna] = DX++;
38
39 }
40 else if (columna == 2)
41 {
42 M[fila, columna] = EX--;
43
44 }
45 else if (columna == 3)
46 {
47 M[fila, columna] = FX++;
48 }
49 else if (columna == 4)
50 {
51 M[fila, columna] = GX--;
52 }
53
C:\Users\ferna\Documents\Programa c\2NDA TAREA\Prog11.cs 2
54
55 }
56
57
58 }
59
60 for (int fila = 0; fila < 5; fila++)
61 {
62 for (int columna = 0; columna < 5; columna++)
63 {
64 Console.Write(" " + M[columna, fila] + " ");
65 }
66 Console.WriteLine("");
67 }
68 Console.ReadKey();
69 }
70 }
71 }
72
73
74
75
76
77
78
79
80
81
82
83
84
85

You might also like