Introduction
Control Statement
- Program to find reverse of the number
- Program to Check Armstrong Number
- Program to find the sum of Natural Numbers using Recursion
- Calculator Program
- Program to identify day of week
- Program to print Fibonacci series
- Check Whether the Number is Even or Odd in C++
- Program to check whether the number is prime or not
- Program to check vowel or constant
Function
- Program to Shutdown and restart Computer
- Program to find the area of triangle
- Program to find LCM
- Program to check prime number using Functions
- Program to convert Binary to Decimal Number
- Program to convert Decimal to Binary Number
- Program to convert Binary to Octal Number
- Program to convert Octal to Binary Number
- Program to find reverse of the sentence using Recursion
Array
Pointer
OOPS
No Examples found for this topic - CodeHelpPro
Program to the sum of natural numbers
In this example, we will learn how to sum natural numbers using the c++ programming language.
To understand this example, You must have knowledge in following topics
To sum the natural number, We will use for loop. We will loop upto the number we want to calculate sum. Let’s look and example to make clear concepts.
#include <iostream>
using namespace std;
int main() {
int n, sum = 0;
cout << "Enter a positive integer: ";
cin >> n;
for (int i = 1; i <= n; ++i) {
sum += i;
}
cout << "Sum = " << sum;
return 0;
}
The output of above program is
Enter a positive integer: 10
Sum = 55
Subscribe
Login
0 Comments
Inline Feedbacks
View all comments