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.
#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;
}
}
Comments
Leave a comment