Given a number N, print sum of all even numbers from 1 to N.
Input Format :
Output Format :
Sample Input 1 :
Sample Output 1 :
C/C++,java,python c++ keywords, identifiers, data types,variables,modifiers,storage classes,operators,for loop ,while loop,do while loop,if else statement,nested loops,break continue goto statement,functions ,call by value call by reference ,arrays ,strings,pointers,data structures ,classes and objects,inheritance,polymorphism,operator overloading,function overloading,data abstraction,data encapsulation,dynamic memory allocation for array and objects,function templates,class templates,
Integer N
Required Sum
6
12
code
#include<iostream>
using namespace std;
int main()
{
int n,i,sum=0;
cin>>n;
for(i=2 ; i<=n ; i+=2)
{
sum += i;
}
cout << sum <<endl;
}
0 comments:
Post a Comment