C sharp - me pueden pasar este programa a c# o c

 
Vista:
sin imagen de perfil

me pueden pasar este programa a c# o c

Publicado por Diego Pedro (1 intervención) el 26/04/2022 03:11:08
import java.util.Scanner;

public class Programa1 {

static Scanner leer = new Scanner(System.in);
static int[] listaNumeros = new int[10];
static int index = 0;

public static void main(String[] args) {

int opc;
do{
System.out.println("Elige una opcion:\n"
+ "1 Insertar un elemento a la lista.\n"
+ "2 Mostrar la lista.\n"
+ "3 Buscar elemento en la lista y su posicion.\n"
+ "4 Actualizar los datos de un elemento.\n"
+ "5 Borrar un elemento de la lista.\n"
+ "6 Ordenar los datos.\n"
+ "7 Salir.\n"
+ "Digite el numero de su opcion:");
opc = leer.nextInt();
switch(opc){
case 1:
if(index == 21){
System.out.println("La lista esta llena.");
}else{
insertar();
}
break;
case 2:
mostrar();
break;
case 3:
System.out.println(buscar());
break;
case 4:
actualizar();
break;
case 5:
borrar();
break;
case 6:
ordenar();
break;
case 7:
System.out.println("Adios.");
break;
default:
System.out.println("Opción invalida.");
}
System.out.println("Presione cualquier tecla para continuar...");
leer.next();
System.out.println("\n\n");
}while(opc < 7 && opc > 0);

}

public static void insertar(){

System.out.println("Digite el número a insertar:");
int num = leer.nextInt();
listaNumeros[index] = num;
index++;
System.out.println("Se inserto exitosamente.");

}

public static void mostrar(){
for (int i = 0; i < index; i++) {
System.out.print(listaNumeros[i] + " ");
}
System.out.println();
}

public static String buscar(){
System.out.println("Digite el número a buscar:");
int busc = leer.nextInt();
for (int i = 0; i < index; i++) {
if(listaNumeros[i] == busc){
return "Se encontró en la posición " + (i + 1);
}
}
return "No se encontró.";
}

public static void actualizar(){
System.out.println("Digite la posición a actualizar:");
int pos = leer.nextInt();
System.out.println("Digite el dato:");
int num = leer.nextInt();
if(pos > index){
System.out.println("No se han dado datos en esta posición.");
}else{
listaNumeros[pos - 1] = num;
System.out.println("Se actualizó exitosamente.");
}
}

public static void borrar(){
System.out.println("Digite la posición a borrar:");
int pos = leer.nextInt();
if(pos > index){
System.out.println("No se han dado datos en esta posición.");
}else{
for(int i = pos - 1; i < (index - 1); i++){
listaNumeros[i] = listaNumeros[i + 1];
}
index--;
}
}

public static void ordenar() {
int aux;
for (int i = 0; i < (index - 1); i++) {
for (int j = (index - 1); j > 0; j--) {
if (listaNumeros[j] < listaNumeros[j - 1]) {
aux = listaNumeros[j - 1];
listaNumeros[j - 1] = listaNumeros[j];
listaNumeros[j] = aux;
}
}
}
}

}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 373
Plata
Ha aumentado su posición en 2 puestos en C sharp (en relación al último mes)
Gráfica de C sharp

me pueden pasar este programa a c# o c

Publicado por Agustin (171 intervenciones) el 26/04/2022 21:22:18
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
var listaNumeros = new int[10];
var index = 0;
 
var nextInt = () => {
    int? val = null;
    while (val == null)
        val = int.TryParse(Console.ReadLine(), out var v) ? v : null;
    return val.Value;
};
 
var opc = 0;
 
do
{
    Console.WriteLine(@"Elige una opcion:
1 Insertar un elemento a la lista.
2 Mostrar la lista.
3 Buscar elemento en la lista y su posicion.
4 Actualizar los datos de un elemento.
5 Borrar un elemento de la lista.
6 Ordenar los datos.
7 Salir.
Digite el numero de su opcion:");
 
    opc = nextInt();
 
    switch (opc)
    {
        case 1:
            if (index == 9)
                Console.WriteLine("La lista esta llena.");
            else
                Insertar();
            break;
        case 2:
            Mostrar();
            break;
        case 3:
            Console.WriteLine(Buscar());
            break;
        case 4:
            Actualizar();
            break;
        case 5:
            Borrar();
            break;
        case 6:
            Ordenar();
            break;
        case 7:
            Console.WriteLine("Adios.");
            break;
        default:
            Console.WriteLine("Opción invalida.");
            break;
    }
 
    Console.WriteLine("Presione cualquier tecla para continuar...");
    Console.ReadKey();
    Console.WriteLine();
}
while (opc is < 7 and > 0);
 
void Insertar()
{
    Console.Write("Digite el número a insertar: ");
    listaNumeros[index] = nextInt();
    index++;
    Console.WriteLine("Se inserto exitosamente.");
}
 
void Mostrar()
{
    foreach (var n in listaNumeros)
        Console.Write($"{n} ");
    Console.WriteLine();
}
 
string Buscar()
{
    Console.Write("Digite el número a buscar: ");
    int busc = nextInt();
 
    for (int i = 0; i < index; i++)
        if (listaNumeros[i] == busc)
            return "Se encontró en la posición " + (i + 1);
 
    return "No se encontró.";
}
 
void Actualizar()
{
    Console.Write("Digite la posición a actualizar: ");
    var pos = nextInt();
    Console.WriteLine();
    Console.Write("Digite el dato: ");
    var num = nextInt();
    if (pos > index)
    {
        Console.WriteLine("No se han dado datos en esta posición.");
    }
    else
    {
        listaNumeros[pos - 1] = num;
        Console.WriteLine("Se actualizó exitosamente.");
    }
}
 
void Borrar()
{
    Console.Write("Digite la posición a borrar: ");
    int pos = nextInt();
    if (pos > index)
        Console.WriteLine("No se han dado datos en esta posición.");
    else
        for (int i = pos - 1; i < (index - 1); i++)
            listaNumeros[i] = listaNumeros[i + 1];
        index--;
}
 
void Ordenar()
{
    int aux;
    for (int i = 0; i < (index - 1); i++)
        for (int j = (index - 1); j > 0; j--)
            if (listaNumeros[j] < listaNumeros[j - 1])
            {
                aux = listaNumeros[j - 1];
                listaNumeros[j - 1] = listaNumeros[j];
                listaNumeros[j] = aux;
            }
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar