Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. //Philip Alonzo
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.  
  9. int firstNum;
  10. int secondNum;
  11. int sum = 0;
  12. int squareSum = 0;
  13.  
  14. cout << "Please enter two integers. The first must be less than the second." << endl;
  15. cout << "1st: ";
  16. cin >> firstNum;
  17. cout << "2nd: ";
  18. cin >> secondNum;
  19.  
  20. while (firstNum >= secondNum)
  21. {
  22. cout << "The first integer must be less than the second integer." << endl;
  23. cout << "1st: ";
  24. cin >> firstNum;
  25. cout << "2nd: ";
  26. cin >> secondNum;
  27.  
  28. }
  29.  
  30. cout << "All odd integers:" << endl;
  31. for (int i = firstNum; i <= secondNum; i++){
  32.  
  33. if (i % 2 != 0){
  34. cout << i << " ";
  35.  
  36. }
  37.  
  38. }
  39.  
  40. cout << "\nSum of all even integers:" << endl;
  41. for (int i = firstNum; i <= secondNum; i++)
  42. {
  43.  
  44. if (i % 2 == 0){
  45. sum = sum + i;
  46. cout << i << " ";
  47. }
  48.  
  49. }
  50. cout << "\n=" << sum << endl;
  51.  
  52. cout << "\nThe square of all numbers between and including first and second integer:" << endl;
  53. for (int i = firstNum; i <= secondNum; i++)
  54. {
  55.  
  56. if (i % 2 == 0){
  57. cout << (i*i) << " ";
  58. }
  59. if (i % 2 != 0){
  60. cout << (i*i) << " ";
  61. }
  62. }
  63.  
  64. cout << "\nThe sum of odd integers squared between first and second integer:" << endl;
  65. for (int i = firstNum; i <= secondNum; i++)
  66. {
  67.  
  68. if (i % 2 != 0){
  69. squareSum += i*i;
  70. }
  71.  
  72. }
  73. cout << squareSum << endl;
  74. return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement