Answer to Question #296933 in C++ for Annie

Question #296933

Write algorithm using pseudocode and flowchart that uses while loops to perform the




following steps:




i. Prompt the user to input two integers: firstNum and secondNum note that firstNum




must be less than secondNum.




ii. Output all odd numbers between firstNum and secondNum.




iii. Output the sum of all even numbers between firstNum and secondNum.




iv. Output the numbers and their squares between firstNum and secondNum.




v. Output the sum of the square of the odd numbers between firstNum and secondNum.




b. Redo Exercise (a) using for loops.




c. Redo Exercise (a) using do. . .while loo

1
Expert's answer
2022-02-12T11:07:53-0500
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>




using namespace std;




int main()
{
	int firstNum=0, secondNum=0;


	std::cout << "Enter firstNum : ";
	std::cin >> firstNum;
	
	std::cout << "Enter firstNum : ";
	std::cin >> secondNum;


	if (!(firstNum < secondNum))
	{
		std::cout << "firstNum > secondNum  , error\n";
		system("pause");
		return 0;
	}
	//
	std::cout << "All odd numbers between firstNum and secondNum : ";
	for (int i = firstNum; i < secondNum; i++)
	{
		if (i % 2 == 1)
		{
			std::cout << i << '\t';
		}
	}
	std::cout << '\n';
	//
	std::cout << "The sum of all even numbers between firstNum and secondNum : ";
	int sum = 0;
	for (int i = firstNum; i < secondNum; i++)
	{
		if (i % 2 == 0)
		{
			sum += i;
		}
	}
	std::cout << sum<<'\n';
	//
	std::cout << "The numbers and their squares between firstNum and secondNum. : ";
	for (int i = firstNum; i < secondNum; i++)
	{


		std::cout <<"{" << i << " , "<<i*i<<"} ";


	}
	std::cout << '\n';








	system("pause");


	return 0;


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog