C++ Program to Find Sum of First n Natural Numbers

Here I have given C++ program to find sum of first n natural numbers. First of all I am reading value of n and then calculating the sum using for loop.

If you have any doubts related to the program then feel free to ask in comment section.

C++ Program to Find Sum of First n Natural Numbers

 

Output

How many numbers? 5

Sum=15

11 thoughts on “C++ Program to Find Sum of First n Natural Numbers

  1. Neeraj Mishra

    @varun long is a type of datatype same as int,float etc, its range is higher than int……..sum=0 means initial value of sum is 0……..

    Reply
  2. Fatal1ty

    Neeraj Mishra, dude, this is old C++. I mean the turbo compiler is almost a decade old, so i suggest you start writing programs using a mordern compiler like g++,minigw,visual c++ etc..

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *