Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #define tmax 10
  5.  
  6. int pile[tmax];
  7. int sommet;
  8.  
  9. void initpile(void) {
  10. sommet += 1;
  11. }
  12.  
  13. void empiler(int ent) {
  14. if (sommet < tmax-1) {
  15. sommet ++;
  16. pile[sommet] = ent;
  17. }
  18. }
  19.  
  20. void depiler (int * ent) {
  21. if (sommet > -1) {
  22. *ent = pile[sommet];
  23. sommet --;
  24. }
  25. }
  26.  
  27. int pile_vide (void) {
  28. return(sommet == -1);
  29. }
  30.  
  31. int convertir(char c) {
  32. return (int)(c -'0');
  33. }
  34.  
  35. void traiter_vcour(char c) {
  36. int ent;
  37. int a;
  38. int b;
  39. int resultat;
  40. if(isdigit(c) == 1) {
  41. empiler(convertir(c));
  42. }
  43. else {
  44. depiler(&a);
  45. depiler(&b);
  46. switch(c) {
  47. case '+' : empiler(a+b); break;
  48. case '-' : empiler(b-a); break;
  49. case '*' : empiler(a*b); break;
  50. case '/' : empiler(b/a); break;
  51. }
  52. }
  53. }
  54.  
  55. int main () {
  56. char c;
  57. initpile();
  58. int valeur;
  59. scanf("%c", &c);
  60. while(c!='\n') {
  61. traiter_vcour(c);
  62. scanf("%c", &c);
  63. }
  64. depiler(&valeur);
  65. printf("%i", valeur);
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement