Loading .vscode/ipch/.DS_Store 0 → 100644 +6 KiB File added.No diff preview for this file type. View file testMatrix.c 0 → 100644 +63 −0 Original line number Diff line number Diff line #include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; int main(int argc, char *argv[]) { ifstream myfile(argv[1]); ifstream myfile1(argv[2]); ofstream outfile("res.txt"); if (myfile.is_open() && myfile1.is_open()) { int arrSize = 0; double arr[1001805]; // Ideally this would be a vector, but you said array double arr1[1001805]; // Ideally this would be a vector, but you said array double res[1001805]; // Ideally this would be a vector, but you said array while ( true) { double x; myfile >> x; if (myfile.eof()) break; arr[arrSize++] = x; } arrSize=0; while (true) { double x; myfile1 >> x; if (myfile1.eof()) break; arr1[arrSize] = x; res[arrSize]=arr[arrSize]-arr1[arrSize]; outfile<<arrSize<<" "<<fixed<<setprecision(20)<< res[arrSize]<<" "<<arr[arrSize]<<" "<<arr1[arrSize]<<"\n"; arrSize++; } // I should have closed the file here, but as the program was ending I was lazy } } else { cout << "Unable to open file"; } outfile.close(); myfile.close(); myfile1.close(); return 0; } Loading
testMatrix.c 0 → 100644 +63 −0 Original line number Diff line number Diff line #include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; int main(int argc, char *argv[]) { ifstream myfile(argv[1]); ifstream myfile1(argv[2]); ofstream outfile("res.txt"); if (myfile.is_open() && myfile1.is_open()) { int arrSize = 0; double arr[1001805]; // Ideally this would be a vector, but you said array double arr1[1001805]; // Ideally this would be a vector, but you said array double res[1001805]; // Ideally this would be a vector, but you said array while ( true) { double x; myfile >> x; if (myfile.eof()) break; arr[arrSize++] = x; } arrSize=0; while (true) { double x; myfile1 >> x; if (myfile1.eof()) break; arr1[arrSize] = x; res[arrSize]=arr[arrSize]-arr1[arrSize]; outfile<<arrSize<<" "<<fixed<<setprecision(20)<< res[arrSize]<<" "<<arr[arrSize]<<" "<<arr1[arrSize]<<"\n"; arrSize++; } // I should have closed the file here, but as the program was ending I was lazy } } else { cout << "Unable to open file"; } outfile.close(); myfile.close(); myfile1.close(); return 0; }