Guest User

Untitled

a guest
May 4th, 2014
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main( int argc, char *argv[] )
  4. {
  5.   int num1 = 0;
  6.   int num2 = 0;
  7.   char op = '\0';
  8.  
  9.   FILE* fin = fopen("input.txt", "r");
  10.   FILE* fout = fopen("output.txt", "w");
  11.  
  12.   while ( fscanf(fin, "%d", &num1) != EOF ) {
  13.     while ( fscanf(fin, " %c", &op) && op != ';' ) {
  14.       fscanf(fin, "%d", &num2);
  15.       if ( op == '+' )
  16.         num1 += num2;
  17.       else if ( op == '-' )
  18.         num1 -= num2;
  19.       else if ( op == '*' )
  20.         num1 *= num2;
  21.       else if ( op == '/' )
  22.         num1 /= num2;
  23.     }
  24.     fprintf(fout, "%d;\n", num1);
  25.   }
  26.  
  27.   fclose(fin);
  28.   fclose(fout);
  29.  
  30.   return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment