Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <fstream>
- #include <iostream>
- using namespace std;
- double multic(double* vect, int size, double b)
- {
- double s = 1;
- for (int i = 0; i < size; ++i)
- {
- if(vect[i] > 0 && b <= vect[i])
- s = s * vect[i];
- }
- return s;
- }
- int main()
- {
- ifstream fileIn;
- fileIn.open("input.txt");
- if (!fileIn)
- {
- cout << "Error: File not found" << endl;
- system("pause");
- return 0;
- }
- int size = 0;
- while (!fileIn.eof())
- {
- double a;
- fileIn >> a;
- size++;
- }
- fileIn.seekg(0, ios_base::beg); //каретка на начало
- double param;
- fileIn >> param;
- if (fileIn.fail())
- {
- cout << "Error: Incorrect value of parametr" << endl;
- system("pause");
- return 0;
- }
- double *arr = new double[size];
- int j = 0;
- while (!fileIn.eof())
- {
- double a;
- fileIn >> a;
- if (fileIn.fail())
- {
- cout << "Error: Incorrect value of element" << endl;
- system("pause");
- return 0;
- }
- arr[j] = a;
- j++;
- }
- fileIn.close();
- double result = multic(arr, size - 1, param);
- cout << "Array: ";
- for (int i = 0; i < size - 1; i++)
- {
- cout << arr[i] << ' ';
- }
- delete[] arr;
- cout << endl << "Result: " << result << endl;
- ofstream fileOut;
- fileOut.open("output.txt");
- fileOut << "Result: " << result;
- fileOut.close();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement