Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int firstNum;
  7. int secondNum;
  8. int evenSum;
  9. int numDiff;
  10. int numSquare;
  11. int oddSquare;
  12. int squareSum = 0;
  13.  
  14.  
  15. cout << "Enter the first number: ";
  16. cin>> firstNum;
  17.  
  18. cout << "Enter the second number: ";
  19. cin>> secondNum;
  20.  
  21. if (firstNum > secondNum)
  22. {
  23. cout<<"The second number must be greater than the first number"<<endl;
  24. cin>> secondNum;
  25. }
  26. cout<<"\n first number: "<< firstNum<<endl;
  27. cout<<"\n second number: "<< secondNum<<endl;
  28.  
  29.  
  30. cout<<"\n All Odd Numbers between First Number and Second Number: "<<endl;
  31. for (int i = firstNum; i <= secondNum; i++)
  32. {
  33. if(i%2 == 1)
  34. cout<< i << endl;
  35. }
  36.  
  37. cout<<"\n Sum of all Even Numbers between First Number and Second Number: "<<endl;
  38. evenSum = 0;
  39. for (int i = firstNum; i <= secondNum; i++)
  40. {
  41. if(i%2 == 0)
  42. evenSum += i;
  43. }
  44. cout<<evenSum << endl;
  45.  
  46. cout<<"\n Numbers and their Squares"<<endl;
  47. numDiff = secondNum - firstNum;
  48.  
  49. if(numDiff <=10 )
  50. {
  51.  
  52. for (int i=firstNum; i<=secondNum; i++)
  53. {
  54.  
  55. numSquare = i*i;
  56. cout<<"Number: " << i << ", Squared: "<< numSquare<< endl;
  57. }
  58. }
  59. else
  60. for(int i=firstNum; i<firstNum+10;i++)
  61. {
  62.  
  63. numSquare = i*i;
  64. cout<<"Number: "<<i <<", Squared: "<< numSquare<< endl;
  65. }
  66. cout<<"\nSum of Squares of Odd integers between First Number and Second Number"<<endl;
  67.  
  68. for(int i=firstNum; i<=secondNum;i++)
  69. {
  70. if(i%2==1)
  71. {
  72. oddSquare = i*i;
  73. squareSum += oddSquare;
  74. }
  75. }
  76.  
  77. cout<<"\n"<<squareSum<<endl;
  78.  
  79. return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement