Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #define size 10
- double tab[size];
- int elem=0;
- void push(double liczba)
- {
- if (elem>=10)
- printf("przekroczono rozmiar stosu");
- else
- {
- printf("dodano element %f na indeksie %d\n",liczba,elem);
- tab[elem]=liczba;
- elem++;
- }
- }
- double pop()
- {
- if (elem>0)
- {
- double element=tab[elem];
- elem--;
- return element;
- }
- else
- {
- printf("stos pusty");
- return;
- }
- }
- int main()
- {
- char ch;
- while(1)
- {
- ch=getchar();
- if (ch=='q')
- break;
- if(isdigit(ch))
- {
- int liczba=ch-'0';
- push(liczba);
- }
- if (!strcmp(ch,"+"))
- {
- double x=pop();
- double y=pop();
- double w=x+y;
- push(w);
- }
- else if (!strcmp(ch,"="))
- {
- double x=pop();
- printf("sciagnieto %f",x);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement