#include <iostream>
using namespace std;
void main()
{
int i,n,sum=0;
cout<<"input number of terms :";
cin>>n;
cout<<"the odd number are:";
for(i=1;i<=n;i++)
{
if(i%2!=0)
{cout<<i<<endl;
sum+=i;}
}
cout<<"the sum of odd natural number upto"<<n<<"terms"<<sum<<endl;
system("pause");
}
Write a program in C++ to display the n terms of odd natural number and their sum . .
Reviewed by Unknown
on
May 18, 2017
Rating:
No comments: