Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int firstNum;
- int secondNum;
- int evenSum;
- int numDiff;
- int numSquare;
- int oddSquare;
- int squareSum = 0;
- cout << "Enter the first number: ";
- cin>> firstNum;
- cout << "Enter the second number: ";
- cin>> secondNum;
- if (firstNum > secondNum)
- {
- cout<<"The second number must be greater than the first number"<<endl;
- cin>> secondNum;
- }
- cout<<"\n first number: "<< firstNum<<endl;
- cout<<"\n second number: "<< secondNum<<endl;
- cout<<"\n All Odd Numbers between First Number and Second Number: "<<endl;
- for (int i = firstNum; i <= secondNum; i++)
- {
- if(i%2 == 1)
- cout<< i << endl;
- }
- cout<<"\n Sum of all Even Numbers between First Number and Second Number: "<<endl;
- evenSum = 0;
- for (int i = firstNum; i <= secondNum; i++)
- {
- if(i%2 == 0)
- evenSum += i;
- }
- cout<<evenSum << endl;
- cout<<"\n Numbers and their Squares"<<endl;
- numDiff = secondNum - firstNum;
- if(numDiff <=10 )
- {
- for (int i=firstNum; i<=secondNum; i++)
- {
- numSquare = i*i;
- cout<<"Number: " << i << ", Squared: "<< numSquare<< endl;
- }
- }
- else
- for(int i=firstNum; i<firstNum+10;i++)
- {
- numSquare = i*i;
- cout<<"Number: "<<i <<", Squared: "<< numSquare<< endl;
- }
- cout<<"\nSum of Squares of Odd integers between First Number and Second Number"<<endl;
- for(int i=firstNum; i<=secondNum;i++)
- {
- if(i%2==1)
- {
- oddSquare = i*i;
- squareSum += oddSquare;
- }
- }
- cout<<"\n"<<squareSum<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement