Answer to Question #132725 in C++ for phile

Question #132725
Write a program that uses for loops to perform the following steps:
a. Prompt the user to input two integers: firstNum and secondNum
(firstNum must be less than secondNum).
b. Output all odd numbers between firstNum and secondNum.
c. Output the sum of all even numbers between firstNum and secondNum.
d. Output the numbers and their squares between 1 and 10.
e. Output the sum of the square of the odd numbers between firstNum and secondNum.
f. Output all uppercase letters
1
Expert's answer
2020-09-12T08:13:10-0400
int firstNum, secondNum, count=0, sum=0;
	cout << "a) Input two integers: firstNum and secondNum (firstNum must be less than secondNum)" << endl;
	cin >> firstNum >> secondNum;
	cout << endl;
	cout << "b) ";
	for (int i = firstNum; i <= secondNum; ++i)
		if (i % 2 == 1)
			cout << i << " ";
	cout << endl;
	for (int i = firstNum; i <= secondNum; ++i)
		if (i % 2 == 0)
			count += i;
	cout << "c) Sum of all even numbers = " << count<<endl;
	cout << "d) ";
	for (int i = 1; i <= 10; ++i)
		cout << "Number = " << i << " and square = " << i * i << endl;
	for (int i = firstNum; i <= secondNum; ++i)
		if (i % 2 == 1)
			sum += i * i;
	cout << "e) Sum of the square of the odd numbers: " << sum << endl;
	cout << "f) ";
	for (int i = 0; i < 26; ++i)
		cout << char(i + 65) << "  ";

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
APPROVED BY CLIENTS