C++ Program to print 1 to N numbers
Take any integer as input iterate the loop from 1 to n.
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
0 Comments