Print the Numbers from 1 to N in C++. How to print all the numbers from 1 to N in C++?

C++ Program to print 1 to N numbers

        Take any integer as input iterate the loop from 1 to n.



Code

#include<bits/stdc++.h>
using namespace std;


int main(){
    cout<<"Enter a number "<<endl;         //Requesting a number


    int n;                                              //variable to store entered number
    cin>>n;                                         //Reading input
    
    cout<<"The numbers are "
    
    for(int i=1;i<=n;i++){                  //Loop to print the numbers from 1 to N
        cout<<i<<" ";
    }
    return 0;
}


Input 

7


Output

Enter a number 

The numbers are 1 2 3 4 5 6 7 



Post a Comment

0 Comments