Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Philip Alonzo
- #include <iostream>
- using namespace std;
- int main()
- {
- int firstNum;
- int secondNum;
- int sum = 0;
- int squareSum = 0;
- cout << "Please enter two integers. The first must be less than the second." << endl;
- cout << "1st: ";
- cin >> firstNum;
- cout << "2nd: ";
- cin >> secondNum;
- while (firstNum >= secondNum)
- {
- cout << "The first integer must be less than the second integer." << endl;
- cout << "1st: ";
- cin >> firstNum;
- cout << "2nd: ";
- cin >> secondNum;
- }
- cout << "All odd integers:" << endl;
- for (int i = firstNum; i <= secondNum; i++){
- if (i % 2 != 0){
- cout << i << " ";
- }
- }
- cout << "\nSum of all even integers:" << endl;
- for (int i = firstNum; i <= secondNum; i++)
- {
- if (i % 2 == 0){
- sum = sum + i;
- cout << i << " ";
- }
- }
- cout << "\n=" << sum << endl;
- cout << "\nThe square of all numbers between and including first and second integer:" << endl;
- for (int i = firstNum; i <= secondNum; i++)
- {
- if (i % 2 == 0){
- cout << (i*i) << " ";
- }
- if (i % 2 != 0){
- cout << (i*i) << " ";
- }
- }
- cout << "\nThe sum of odd integers squared between first and second integer:" << endl;
- for (int i = firstNum; i <= secondNum; i++)
- {
- if (i % 2 != 0){
- squareSum += i*i;
- }
- }
- cout << squareSum << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement