C++ program to print the natural numbers using for loop
kw.cpp
#include<iostream>usingnamespacestd;intmain(){intn,i;cout<<"How many numbers you want to print ";cin>>n;for(i=1;i<=n;i++)cout<<i<<" ";cout<<"\n";return0;}
Output
kodingwindow@kw:~$ g++ kw.cpp kodingwindow@kw:~$ ./a.out
How many numbers you want to print 10
1 2 3 4 5 6 7 8 9 10
kodingwindow@kw:~$
C++ program to print the natural numbers using while loop
kw.cpp
#include<iostream>usingnamespacestd;intmain(){intn,i;cout<<"How many numbers you want to print ";cin>>n;i=1;while(i<=n){cout<<i<<" ";i++;}cout<<"\n";return0;}
Output
kodingwindow@kw:~$ g++ kw.cpp kodingwindow@kw:~$ ./a.out
How many numbers you want to print 10
1 2 3 4 5 6 7 8 9 10
kodingwindow@kw:~$
Dear User, Thank you for visitng Kodingwindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.
Dear User, We are grateful for your interest in the Kodingwindow Android app. We intend to soon make it available on the Google Play Store. Currently, Android versions 10 and up require manual apk installations. Would you like to get the app?