Advertisement
Alx09

Untitled

Mar 31st, 2020
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.  
  6. int main() {
  7. double stiva[100];
  8. char numar[20];
  9. unsigned varf = 0;
  10. printf("Pentru a inchide programul introduceti \n");// sa se opresca una 0 e neutru la adunare
  11. do { // de aia am ales asa
  12. printf("st[%u] = ", varf); scanf("%s", &numar);
  13. if (numar[0] == '0')
  14. return 0;
  15. else if (numar[0] == '+' && varf)
  16. printf("Rezultatul este: %f \n", stiva[varf - 1]);
  17. else if (numar[0] == ',' && varf)
  18. --varf;
  19. else if (numar[0] == '.')
  20. varf = 0;
  21. else if (varf)
  22. stiva[varf] = stiva[varf++ - 1] + atof(numar);
  23. else if (strchr("+,.", numar[0]))
  24. printf("Introduceti elemente in stiva!\n");
  25. else
  26. stiva[varf++] = atof(numar);
  27. } while (1);
  28. system("pause");
  29. return 0;
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement