TUTORIALS

C++ Program to print n odd numbers within range

Written By: Chaitra M
Created at: 28-June-2023 20:36:19
Modified at: 28-June-2023 20:36:39

Program


#include <iostream>

using namespace std;

int main()
{
    int start_range, end_range;

    cout << "Enter the starting range: ";
    cin >> start_range;

    cout << "Enter the ending range: ";
    cin >> end_range;

    cout << "Odd numbers in given range are:" << endl;
    for (int i = start_range; i <= end_range; i++)

        if (i % 2 != 0)
            cout << i << " ";
    
    cout << endl;

    return 0;
}

Output


$ g++ print-n-odd-numbers-within-range.cpp 
$ ./a.out 
Enter the starting range: 4
Enter the ending range: 26
Odd numbers in given range are:
5 7 9 11 13 15 17 19 21 23 25

Article Tags:
  • Number
There are no likes. Be the first one to like
Likes: 0
Comments: 0