how to print odd numbers in a given range using c++ code example
Example 1: c++ print the amount of odd integer between n and m
#include <iostream>
using namespace std;
void evenNumbers(int n)
{
int i;
for (i = 1; i <= n; i++) {
if (i % 2 == 0)
cout << i << " ";
}
cout << "\n";
}
void oddNumbers(int n)
{
int i;
for (i = 1; i <= n; i++) {
if (i % 2 != 0)
cout << i << " ";
}
cout << "\n";
}
int main()
{
int N;
cout << "Enter the value of N (limit): ";
cin >> N;
cout << "EVEN numbers are...\n";
evenNumbers(N);
cout << "ODD numbers are...\n";
oddNumbers(N);
return 0;
}
Example 2: c++ print the amount of odd integer between n and m
void oddNumbers(int n)
{
int i;
for (i = 1; i <= n; i++) {
if (i % 2 != 0)
cout << i << " ";
}
cout << "\n";
}
int main()
{
int N;
cout << "Enter the value of N (limit): ";
cin >> N;
cout << "EVEN numbers are...\n";
evenNumbers(N);
cout << "ODD numbers are...\n";
oddNumbers(N);
return 0;
}