SOURCE CODE OUTPUT
#include<iostream>
using namespace std;
int main()
{
long num,sum=1;
cout<<"enter the number ";
cin>>num;
cout<<"1";
for(int i=2;i<=num;i++)
{
if(i%2==1)
{
cout<<"+"<<i;
sum+=i;
}
}
cout<<" = "<<sum;
return 0;
}
using namespace std;
int main()
{
long num,sum=1;
cout<<"enter the number ";
cin>>num;
cout<<"1";
for(int i=2;i<=num;i++)
{
if(i%2==1)
{
cout<<"+"<<i;
sum+=i;
}
}
cout<<" = "<<sum;
return 0;
}
Any questions regarding to program please write in comments.
No comments:
Post a Comment