Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- using namespace std;
- int findoperindex(char* a);
- int main() {
- setlocale(LC_ALL, "Rus");
- FILE* input, *output;
- char str[100];
- double x, y;
- fopen_s(&input, "input.txt", "r");
- fopen_s(&output, "output.txt", "w");
- while (!feof(input)) {
- fgets(str, 40, input);
- printf("%s", str);
- char number1[3], number2[3];
- int index = findoperindex(str);
- int j = 0, g = 0;
- if (index) {
- for (int i = 0; i < strlen(str); i++) {
- if (i < index && str[i] > 47 && str[i] < 58)
- number1[j++] = str[i];
- if (i > index && str[i] > 47 && str[i] < 58)
- number2[g++] = str[i];
- }
- }
- x = atof(number1);
- y = atof(number2);
- switch (str[index]) {
- case '+':
- fprintf(output, "%1.0f %s %1.0f %s %1.0f \n", x, "+", y, "=", x + y);
- break;
- case '-':
- fprintf(output, "%1.0f %s %1.0f %s %1.0f \n", x, "-", y, "=", x - y);
- break;
- case '*':
- fprintf(output, "%1.0f %s %1.0f %s %1.0f \n", x, "*", y, "=", x * y);
- break;
- case '/':
- fprintf(output, "%1.0f %s %1.0f %s %1.2f \n", x, "/", y, "=", x / y);
- break;
- }
- }
- fclose(input);
- fclose(output);
- return 0;
- }
- int findoperindex(char* a) {
- for (int i = 0; i < strlen(a); i++) {
- switch (a[i]) {
- case '+':
- return i;
- case '-':
- return i;
- case '*':
- return i;
- case '/':
- return i;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement