#include<iostream>usingnamespacestd;intmain(){intn,sum;cout<<"———————————————————————————————————————————";cout<<"\nProgram to print the addition of N numbers";cout<<"\n———————————————————————————————————————————";cout<<"\nEnter the number ";cin>>n;if(n>=0){sum=(n*(n+1)/2);cout<<"\nThe sum of first "<<n<<" natural numbers is = "<<sum;}else{cout<<"\nPlease enter +ve number ";}cout<<"\n———————————————————————————————————————————\n";return0;}
Output
kodingwindow@kw:~$ g++ kw.cpp kodingwindow@kw:~$ ./a.out
———————————————————————————————————————————
Program to print the addition of N numbers
———————————————————————————————————————————
Enter the number 10
The sum of first 10 natural numbers is = 55
———————————————————————————————————————————
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, you need to install apk manually. Would you like to get the app? Minimum Requirement(s): Android 10