Connect with a knowledgeable community and get your questions answered on IDNLearn.com. Ask anything and receive comprehensive, well-informed responses from our dedicated team of experts.
Sagot :
Answer:
Explanation:
//Include the required header files.
#include<iostream>
using namespace std;
//Define the main function.
int main()
{
//Define the variables.
int i, sum = 0, sqSum = 0, firstNum = 1, secondNum = 0;
char ch;
//Check for valid input.
while (!(firstNum < secondNum))
{
cout << "Enter starting number: ";
cin >> firstNum;
cout<<"Enter ending number(must be > startingNumber): ";
cin >> secondNum;
}
//Store first number in i
i = firstNum;
//Dispaly the number.
cout << "The odd numbers between " << firstNum
<< " and " << secondNum << " are:\n";
//Iterate between first and second number.
while (i <= secondNum)
{
//Check for even numbers.
//Store the sum
if (i % 2 == 0)
sum = sum + i;
//Print the odd numbers
//Evaluate the square of sum of odd number.
else
{
cout << i << " ";
sqSum = sqSum + i * i;
}
//Increase the value of i.
i++;
}
//Dispaly the sum of even numbers.
cout << "\n\nThe sum of the even numbers is:"
<< sum << endl << endl;
//Dispaly the sum of square of odd number.
cout << "The sum of squares the odd numbers is:"
<< sqSum << endl;
//Set i to 1.
i = 1;
//Dispaly the message.
cout << "\nNumber Square\n";
//Iterate and print number between 1 andd 10
//along with the sum.
while (i <= 10)
{
cout << " " << i << "\t " << i * i << endl;
i++;
}
//USe for visual studio.
system("pause");
//Return the value 0.
return 0;
}
Explanation:
The program code will perform the function listed below using loop.
Prompt the user to input two integers: firstNum and secondNum (firstNum must be less than secondNum). Output all odd numbers between firstNum and secondNum. Output the sum of all even numbers between firstNum and secondNum. Output the numbers and their squares between 1 and 10. Separate the numbers using any amount of spaces. Output the sum of the square of the odd numbers between firstNum and secondNum. Output all uppercase letters.
Hope this helps!
We value your participation in this forum. Keep exploring, asking questions, and sharing your insights with the community. Together, we can find the best solutions. Thank you for trusting IDNLearn.com. We’re dedicated to providing accurate answers, so visit us again for more solutions.