C++ Program to Print First n Odd Numbers using For Loop
Write C++ Program to Print First n Odd Numbers using For Loop
// CPP Program to Print First n Odd Numbers using For Loop #include <iostream> using namespace std; int main() { int n; cout << "Enter Number :--> "; cin >> n; int i = 1, Count; cout << "First " << n << " Odd Numbers :--> "; for(Count = 0; Count < n; i++) { if(i%2 != 0) { cout << i << " "; Count++; } } return 0; }
Output:
Enter Number :--> 8
First 8 Odd Numbers :--> 1 3 5 7 9 11 13 15