Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int zero = 0;
  6.  
  7. int main()
  8. {
  9. int numA, numB;
  10. bool even = true;
  11.  
  12. cout << "x^2+ax+b\n";
  13. cout << "Enter a: ";
  14. cin >> numA;
  15. cout << "Enter b: ";
  16. cin >> numB;
  17. cout << endl;
  18.  
  19. vector<int> v;
  20. vector<int> sum;
  21.  
  22. for (int i = 1; i <= numB; ++i) //find factors of numB and insert into vector
  23. {
  24. if (numB % i == 0)
  25. {
  26. v.push_back(i);
  27. }
  28. }
  29.  
  30. cout << "Factors of " << numB << " are "; //program outputs numbers in vector just cause
  31. for (unsigned int i = 0; i < v.size(); i++)
  32. cout << v[i] << " ";
  33. cout << endl;
  34.  
  35. int maxNum = v.size() - 1;
  36. int currentMax = maxNum, currentLow = 1;
  37. int sumFactors;
  38.  
  39. for (int i = 0; i < v.size(); i++) //programs adds the different factors
  40. {
  41. currentLow = v[i];//determines the lower number to add
  42. cout << currentLow << endl;
  43.  
  44. currentMax = v[maxNum]; //determines the higher number to add
  45. cout << currentMax << endl;
  46. maxNum = maxNum - 1;
  47.  
  48. sumFactors = currentMax + currentLow; //adds the lower and higher numbers
  49. cout << "Factor: " << sumFactors << endl;
  50. sum.push_back(sumFactors);
  51. }
  52.  
  53. bool equalTo = false;
  54. int numUse = 0;
  55. do //program finds what sum equals sumA
  56. {
  57. if (sum[numUse] == numA)
  58. {
  59. cout << sum[numUse] << " is equal to " << numA << endl;
  60. equalTo = true;
  61. }
  62. else
  63. {
  64. numUse++;
  65. }
  66. }while (equalTo == false);
  67.  
  68.  
  69.  
  70. system("pause");
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement