Write a C Program to find out the sum of first n numbers

By | November 2, 2016

Find out the sum of first n numbers


Write a C Program to find out the sum of first n numbers. Here’s simple Program to find out the sum of first n numbers in C Programming Language.


LOGIC : : 

The program asks the user to enter the number of terms he/she would like to evaluate the sum of, which is stored in variable n. Another variable i is assigned value 1, which is used for counting the number of terms in the loop and also as a natural number which is added to the result.

The variable sum stores sum of the natural numbers. The sum is initialized to 0 to avoid addition of garbage numbers.As the program enters the loop, value of i is added to the variable sum which now equals the sum of all natural numbers till i. Then the value of i is increased by 1.

The loop continues as long as the value of i is less than or equal to n as we are calculating the sum of first n natural numbers. When, the loop exits, the result is displayed on the screen.


Below is the source code for C Program to find out the sum of first n numbers which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :



OUTPUT : :



Above is the source code for C Program to find out the sum of first n numbers which is successfully compiled and run on Windows System.The Output of the program is shown above .

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in short interval.


Thanks for reading the post….

Leave a Reply