Print hello world n times in C++ || while loop || C++
In this, we are going to see while loop, the program is based on while loop which prints, Hello world 'n' number of times.

The code given below can be used for TURBO C++ Compiler:-

#include<iostream.h>
#include<conio.h>

void main()
{
    clrscr();
    int n;
    cout << "Enter value of n , How many times to print ? ";
    cin >> n;
    int i = 1;
    while (i <= n)
    {
        cout << "Hello World!\n";
        i++;
    }
    getch();
}
  
    

The code given below can be used for g++/gcc Compiler:-

#include<iostream>
using namespace std;

int main()
{
    int n;
    cout << "Enter value of n , How many times to print ? ";
    cin >> n;
    int i = 1;
    while (i <= n)
    {
        cout << "Hello World!\n";
        i++;
    }
    return 0;
}
  
    

#ENJOY CODING



Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post