bon soir j'ai un probleme avec mon code, en effet je veux creer un code qui fiat une pile .Quand je compile tout marche bi1 mais j'ai ce que je veux c'est la calculette polanaise.Voici mon code:
cordialement.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 #include<stdio.h> #include<stdlib.h> enum bool { FAUX ,VRAI}; typedef struct { int TabPile[10]; int sommetPile; } pile; pile p; float pilevide () { if (p.sommetPile=0) { return VRAI; } else { return FAUX; } } float pilepleine () { int N=10; if (p.sommetPile=N) { return VRAI ; } else { return FAUX; } } float empiler(int x) { if (pilepleine(p)==FAUX) { p.sommetPile++; p.TabPile[p.sommetPile]=x; return VRAI; } else { return FAUX; } } float depiler () { if(pilevide(p)==FAUX) { p.sommetPile--; return p.TabPile[p.sommetPile+1]; } else { return printf("c'est vide\n"); } } int main ( int argc, char** argv) { char c; int nb,nb1,nb2; float resultat; while((c=getchar())!='q') { if (c<='9' && c>='0') { nb=c-48; empiler(nb); } else if ((c=='+') ||(c=='-') || (c=='/') || (c=='*')) { nb1=depiler(); nb2=depiler(); if(c=='+') resultat=nb1+nb2; else if(c=='-') resultat=nb1-nb2; else if(c=='/') resultat=nb1+nb2; else if (c=='*') resultat=nb1/nb2; } } resultat=depiler(); printf("%f \n",resultat); return 0; }
Partager