elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: (TUTORIAL) Aprende a emular Sentinel Dongle By Yapis


  Mostrar Temas
Páginas: [1]
1  Programación / Programación C/C++ / Ayuda Calculadora en: 1 Junio 2018, 23:01 pm
Buen dia, espero puedan ayudarme estoy haciendo un programa de Notacion Polaca, mi problema es que me hace falta una funcion que al leer la cadena esta funcion realice la operacion (como una calculadora).
Por ejemplo:
(2+6)*10=80

Tengo esta funcion pero solo es para numeros de un digito, tengo pensado usar apuntadores pero no se como.

Código:
//MOSTRAMOS EL RESUTALTADO DE LA OPERACION
void resultado(char cadena[100]){
char operador, operandoX, operandoY; //VARIABLES PARA PODER OPERAR
int resultado, pilaResultado[100]; //PILA PARA GUARDAR LOS RESULTADOS

printf("\n\nSolucion");

for(int i = 0, j = -1; i < strlen(cadena); i++){ //RECORREMOS LA CADENA
if((((int(cadena[i])) > 47) && ((int(cadena[i])) < 58))){ //SI SE LEE UN NUMERO ENTONCES SE AGREGA A LA PILA DE RESULTADOS
j++; //AUMETAMOS EL TOPE DE LA PILA
pilaResultado[j] = (int)cadena[i] - 48; //SE CASTEA EL CARECTER Y SE LE RESTAN 48 PARA PODER GUARDAR EL NUMERO QUE SE LEE COMO CARACTER
}else if(cadena[i] == '!'){ //SI SE LEE UNA OPERACION DE NEGACION
operandoX = pilaResultado[j]; //SE TOMA EL ULTIMO VALOR DE LA PILA DE OPERACION
resultado = operandoX * (-1); //SE MULTIPLICA POR -1
pilaResultado[j] = resultado; //SE GURADA EL RESULTADO EN EL TOPE DE LA PILA DE RESULTADOS
printf("\n\t!%i = %i", operandoX, resultado);
}else if(cadena[i] == '+'){ //SI SE LEE UNA OPERACION DE SUMA
operandoX = pilaResultado[j]; //SE EXTRAE EL TOPE DE LA PILA Y SE GUARDA EN OPERANDOX
j--; //SE DISMINUYE EL TOPE DE LA PILA
operandoY = pilaResultado[j]; //SE EXTRAE EL TOPE DE LA PILA Y SE GUARDA EN OPERANDOY
resultado = operandoX + operandoY; //RE OPERAN LAS VARIABLES OPERANDOX Y OPERANDOY
pilaResultado[j] = (int)resultado; //SE GUARDA EL RESULTADO
printf("\n\t%d + %i = %i", operandoY, operandoX, resultado);
}else if(cadena[i] == '-'){ //EN CASO DE QUE SE LEA UNA OPERACION DE RESTA
operandoX = pilaResultado[j];
j--;
operandoY = pilaResultado[j];
resultado = operandoY - operandoX;
pilaResultado[j] = resultado;
printf("\n\t%d - %i = %i", operandoY, operandoX, resultado);
}else if(cadena[i] == '*'){ //EN CASO DE QUE SE LEA UNA OPERACION DE MULTIPLICACION
operandoX = pilaResultado[j];
j--;
operandoY = pilaResultado[j];
resultado = operandoY * operandoX;
pilaResultado[j] = resultado;
printf("\n\t%d * %i = %i", operandoY, operandoX, resultado);
}else if(cadena[i] == '/'){ //EN CASO DE QUE SE LEA UNA OPERACION DE DIVISION
operandoX = pilaResultado[j];
j--;
operandoY = pilaResultado[j];
if(operandoX == 0)
resultado = 0;
else
resultado = operandoY / operandoX;
pilaResultado[j] = resultado;
printf("\n\t%d / %i = %i", operandoY, operandoX, resultado);
}else if(cadena[i] == '^'){ //EN CASO DE QUE SE LEA UNA OPERACION DE EXPONENTE
operandoX = pilaResultado[j];
j--;
operandoY = pilaResultado[j];
resultado = pow(operandoY,operandoX);
pilaResultado[j] = resultado;
printf("\n\t%d ^ %i = %i", operandoY, operandoX, resultado);
}
}
printf("\nResultado: %i", pilaResultado[0]); //SE MUESTRA EL RESULTADO FINAL
}


Nota:No puedo subir el codigo de notacion porque aun no me califican pero en cuanto me califique lo subire.
2  Programación / Java / Ayuda con programa en: 21 Abril 2016, 23:28 pm
Ayuda necesito que el programa diga si una frase es palindromo o no pero solo funciona con palabras espero puedan ayudarme,gracias.

Código:
import java.io.*;
class Palindromo{

public static void main(String[] args) throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);

String cadena="";
String aux="";
int c=1;
System.out.print("Ingresa una palabra o una cadena:_");
cadena = br.readLine();

for(int i = 0; i < cadena.length(); i++){
if (cadena.charAt(i) != cadena.charAt(cadena.length()-1-i)){
c = 0;

}

}
if (c == 1){
System.out.println("Es un palindromo");

}else{
System.out.println("No es un palindromo");
}

}
}
3  Programación / Java / Palindromo en: 21 Abril 2016, 02:57 am
Ayuda necesito hacer un programa que diga si una palabra es un palindromo o no, que lea la palabra al ejecutar y los recorridos se hagan con foreach, en java.
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines