Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int zero = 0;
- int main()
- {
- int numA, numB;
- bool even = true;
- cout << "x^2+ax+b\n";
- cout << "Enter a: ";
- cin >> numA;
- cout << "Enter b: ";
- cin >> numB;
- cout << endl;
- vector<int> v;
- vector<int> sum;
- for (int i = 1; i <= numB; ++i) //find factors of numB and insert into vector
- {
- if (numB % i == 0)
- {
- v.push_back(i);
- }
- }
- cout << "Factors of " << numB << " are "; //program outputs numbers in vector just cause
- for (unsigned int i = 0; i < v.size(); i++)
- cout << v[i] << " ";
- cout << endl;
- int maxNum = v.size() - 1;
- int currentMax = maxNum, currentLow = 1;
- int sumFactors;
- for (int i = 0; i < v.size(); i++) //programs adds the different factors
- {
- currentLow = v[i];//determines the lower number to add
- cout << currentLow << endl;
- currentMax = v[maxNum]; //determines the higher number to add
- cout << currentMax << endl;
- maxNum = maxNum - 1;
- sumFactors = currentMax + currentLow; //adds the lower and higher numbers
- cout << "Factor: " << sumFactors << endl;
- sum.push_back(sumFactors);
- }
- bool equalTo = false;
- int numUse = 0;
- do //program finds what sum equals sumA
- {
- if (sum[numUse] == numA)
- {
- cout << sum[numUse] << " is equal to " << numA << endl;
- equalTo = true;
- }
- else
- {
- numUse++;
- }
- }while (equalTo == false);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement