program in C++ to display the n terms of square natural number and their sum. . 1 4 9 16 ... n Terms
#include <iostream>
using namespace std;
void main()
{
int i,n,sum=0;
cout<<"Input the number of terms : ";
cin>>n;
cout<<"\nThe square natural upto terms are :"<<n;
for(i=1;i<=n;i++)
{
cout<<" "<<i*i;
sum+=i*i;
}
cout<<"The sum of square natural upto 5 terms are"<<sum<<endl;
system ("pause");
}
using namespace std;
void main()
{
int i,n,sum=0;
cout<<"Input the number of terms : ";
cin>>n;
cout<<"\nThe square natural upto terms are :"<<n;
for(i=1;i<=n;i++)
{
cout<<" "<<i*i;
sum+=i*i;
}
cout<<"The sum of square natural upto 5 terms are"<<sum<<endl;
system ("pause");
}
program in C++ to display the n terms of square natural number and their sum. . 1 4 9 16 ... n Terms
Reviewed by Unknown
on
May 21, 2017
Rating:
No comments: