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



 Write a program to add natural numbers up to nth term by using for loop in c++ language. 


#include <iostream>


using namespace std;


int main() {


    int sum =0  ,n ;


    cout<<"Enter the nth term  n = ";


    cin>>n;


     for(int i =1;i<=n; i++)
    {  sum =sum +i ;}


    cout<<"sum of  "<<n<<"th term is = "<<sum

   return 0;
}


  • OUTPUT

Enter the nth term  n = 20
the sum of  20th term is = 210




Comments

Popular posts from this blog

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

Write the program to make substring of a string.

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