Write a program to add even numbers up to nh by using for loop in c++ language.


Write a program to add even numbers  up to nh  by using for loop in c++ language. 

#include<iostream>


using namespace std;


int main()

      int i , n, sum =0;


      cout<<"Add even numbers  up to nth term  "<<endl;


      cout<<"Enter the number of term (nth) = ";
      cin>>n;
     
     for(i=2;i<=n;i=i+2 )//  intialization i=2;
                     // upgradation ,increment by 2


     {  sum =sum + i ;  }


     cout<<"sum of "<<n<<"th term of only even number = "<<sum;
 return 0;
}


  • OUTPUT
Add even numbers  up to nth term  
Enter the number of term (nth) = 15
the sum of 15th term of only even number = 56

Comments

Popular posts from this blog

Write the program to arrange the n queen(queen of chessboard) in n*n matrix such that they can not ATTACK TO eachother.

Write a program to reverse the string. input = google output = elgoole */

Write the program to determine the maximum possible way to reach the end from starting in game board.