fork(1) download
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. char op;
  6. double a,b;
  7. for(;;)
  8. {
  9. printf("Podaj wyrażenie (np: 12*3, ! - konbiec): ");
  10. if(scanf("%lf %c %lf",&a,&op,&b)==3)
  11. {
  12. if(op=='+') printf("%lf + %lf = %lf\n\n",a,b,a+b);
  13. else if(op=='-') printf("%lf - %lf = %lf\n\n",a,b,a-b);
  14. else if(op=='*') printf("%lf * %lf = %lf\n\n",a,b,a*b);
  15. else if(op=='/') printf("%lf / %lf = %lf\n\n",a,b,a/b);
  16. }
  17. else if(getchar()=='!') return 0;
  18. else
  19. {
  20. printf("Niepoprawne wyrażenie\n\n");
  21. while(getchar()!='\n') {}
  22. }
  23. }
  24. }
Success #stdin #stdout 0s 3300KB
stdin
3 + 4
5*8
9-7
12/3
!
stdout
Podaj wyrażenie (np: 12*3, ! - konbiec): 3.000000 + 4.000000 = 7.000000

Podaj wyrażenie (np: 12*3, ! - konbiec): 5.000000 * 8.000000 = 40.000000

Podaj wyrażenie (np: 12*3, ! - konbiec): 9.000000 - 7.000000 = 2.000000

Podaj wyrażenie (np: 12*3, ! - konbiec): 12.000000 / 3.000000 = 4.000000

Podaj wyrażenie (np: 12*3, ! - konbiec):