Sum of Even Numbers till N in C++
Sum of Even Numbers till N
Send Feedback
Sum of Even Numbers till N
Integer N
Required Sum
6
12
#include<iostream>using namespace std;
int main(){
/* Read input as specified in the question. Print output as specified in the question. */ int n; cin>>n; int i=1; int sum=0; while(n>=i){ if(i%2==0)sum+=i; i++; } cout<<sum<<endl; }
Comments
Post a Comment