Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main( int argc, char *argv[] )
- {
- int num1 = 0;
- int num2 = 0;
- char op = '\0';
- FILE* fin = fopen("input.txt", "r");
- FILE* fout = fopen("output.txt", "w");
- while ( fscanf(fin, "%d", &num1) != EOF ) {
- while ( fscanf(fin, " %c", &op) && op != ';' ) {
- fscanf(fin, "%d", &num2);
- if ( op == '+' )
- num1 += num2;
- else if ( op == '-' )
- num1 -= num2;
- else if ( op == '*' )
- num1 *= num2;
- else if ( op == '/' )
- num1 /= num2;
- }
- fprintf(fout, "%d;\n", num1);
- }
- fclose(fin);
- fclose(fout);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment