C++ Program to display n terms of natural number and their sum

#include <iostream>
using namespace std;
void main()
{
int i,n,sum=0;
   cout<<"Input Value of terms : ";
   cin>>n;
   cout<<"The  natural number is :\n"<<n;
   for(i=1;i<=n;i++)
   {
     cout<<i<<endl;
     sum+=i;
   }
   cout<<"The Sum of Natural Number upto n terms : "<<sum<<endl;
system("pause");
}
C++ Program to display n terms of natural number and their sum  C++ Program to display n terms of natural number and their sum Reviewed by Unknown on May 18, 2017 Rating: 5

No comments:

Powered by Blogger.