This is a platform where we can learn how to program in C++ with a lot of example , There are conceptual questions with proper solutions. Here we will learn about C++ programming with easy way from basic to advance.
Write a program to add natural numbers up to 20 by using for loop in c++ language.
Get link
Facebook
X
Pinterest
Email
Other Apps
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
Post a Comment
If you have any doubt ,let me know