Question #284200

Design an algorithm which gets a natural value, n, as its input and calculates odd numbers 

equal or less than n. Then write them in the standard output.


Expert's answer

#include<iostream>

using namespace std;

int main()
{
	int num;
	cout << "Please, enter a value: ";
	cin >> n;
	cout << "All odd numbers are\n";
	for (int i = 0; i <= n; i++)
	{
		if (i % 2 == 1)
			cout << i << endl;
	}
}

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!

LATEST TUTORIALS
APPROVED BY CLIENTS