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.