Write a C++ program to print first 10 even natural numbers using for loop.
#include<iostream> using namespace std; int main() { cout << "The First 10 Even Natural Numbers are\n"; for (int i = 1; i <= 10; i++) { cout << 2 * i << "\n"; } }
C++ program to print first 10 even natural numbers using a while loop
#include<iostream> using namespace std; int main() { cout << "The First 10 Even Natural Numbers are\n"; int i = 1; while (i <= 10) { cout << 2 * i << "\n"; i++; } }
The First 10 Even Natural Numbers are
2
4
6
8
10
12
14
16
18
20
This C++ program displays the first 10 even natural numbers using a do while loop.
#include<iostream> using namespace std; int main() { cout << "The First 10 Even Natural Numbers are\n"; int i = 1; do { cout << 2 * i << "\n"; } while (++i <= 10); }
The First 10 Even Natural Numbers are
2
4
6
8
10
12
14
16
18
20