Write a program to print the sum of following series s=2+4+6+8+10+....+N
Answers
Answered by
1
we can do this by making a loop...
#include<iostream.h>
#include<math.h>
void main()
{
int n, sum=0;
cout<<''Please enter an even number to add the even numbers up to that number'';
cin>>n;
for(int i=2; i<=n; i+2)
{sum=sum+i;
//or sum+=i
}
cout<<"the sum is "<<sum;
}
That's all
#include<iostream.h>
#include<math.h>
void main()
{
int n, sum=0;
cout<<''Please enter an even number to add the even numbers up to that number'';
cin>>n;
for(int i=2; i<=n; i+2)
{sum=sum+i;
//or sum+=i
}
cout<<"the sum is "<<sum;
}
That's all
kartikagarwal20:
Thanks for the help can u also provide me with the flow chart
Similar questions