- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to find sum of first n natural numbers in C++
In this tutorial, we will be discussing a program to find sum of first n natural numbers.
For this we will be provided with an integer n. Our task is to add up, find the sum of the first n natural numbers and print it out.
Example
#include<iostream> using namespace std; //returning sum of first n natural numbers int findSum(int n) { int sum = 0; for (int x=1; x<=n; x++) sum = sum + x; return sum; } int main() { int n = 5; cout << findSum(n); return 0; }
Output
15
- Related Articles
- Sum of first n natural numbers in C Program
- 8085 program to find the sum of first n natural numbers
- Sum of squares of first n natural numbers in C Program?
- C Program for cube sum of first n natural numbers?
- C++ Program for cube sum of first n natural numbers?
- Program for cube sum of first n natural numbers in C++
- Sum of sum of first n natural numbers in C++
- C++ Program for Sum of squares of first n natural numbers?
- Java Program to cube sum of first n natural numbers
- C Program for the cube sum of first n natural numbers?
- Find the sum of first $n$ odd natural numbers.
- PHP program to find the sum of cubes of the first n natural numbers
- Swift Program to Calculate Cube Sum of First n Natural Numbers
- Python Program for cube sum of first n natural numbers
- Java Program to calculate Sum of squares of first n natural numbers

Advertisements