Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #define tmax 10
- int pile[tmax];
- int sommet;
- void initpile(void) {
- sommet += 1;
- }
- void empiler(int ent) {
- if (sommet < tmax-1) {
- sommet ++;
- pile[sommet] = ent;
- }
- }
- void depiler (int * ent) {
- if (sommet > -1) {
- *ent = pile[sommet];
- sommet --;
- }
- }
- int pile_vide (void) {
- return(sommet == -1);
- }
- int convertir(char c) {
- return (int)(c -'0');
- }
- void traiter_vcour(char c) {
- int ent;
- int a;
- int b;
- int resultat;
- if(isdigit(c) == 1) {
- empiler(convertir(c));
- }
- else {
- depiler(&a);
- depiler(&b);
- switch(c) {
- case '+' : empiler(a+b); break;
- case '-' : empiler(b-a); break;
- case '*' : empiler(a*b); break;
- case '/' : empiler(b/a); break;
- }
- }
- }
- int main () {
- char c;
- initpile();
- int valeur;
- scanf("%c", &c);
- while(c!='\n') {
- traiter_vcour(c);
- scanf("%c", &c);
- }
- depiler(&valeur);
- printf("%i", valeur);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement