c++ print the amount of odd integer between n and m code example
Example 1: c++ print the amount of odd integer between n and m
// C++ program to print all
// Even and Odd numbers from 1 to N
using namespace std;
// function : evenNumbers
// description: to print EVEN numbers only.
void evenNumbers(int n)
{
int i;
for (i = 1; i <= n; i++) {
//condition to check EVEN numbers
if (i % 2 == 0)
cout << i << " ";
}
cout << "\n";
}
// function : oddNumbers
// description: to print ODD numbers only.
void oddNumbers(int n)
{
int i;
for (i = 1; i <= n; i++) {
//condition to check ODD numbers
if (i % 2 != 0)
cout << i << " ";
}
cout << "\n";
}
// main code
int main()
{
int N;
// input the value of 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++) {
//condition to check ODD numbers
if (i % 2 != 0)
cout << i << " ";
}
cout << "\n";
}
// main code
int main()
{
int N;
// input the value of 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;
}