C Program for Sum Of N Natural Numbers
Find the Sum of N Natural Numbers in C
Given an integer input num, the objective is to write a code to find the Sum of N Natural Numbers in C. To do so we iterate and add all the numbers until num.
Example: Input : 5 Output : 1 + 2 + 3 + 4 + 5 = 15
Algorithm
The Algorithm for the above problem is as follows,
- Step 1. Start
- Step 2. Enter a number (N).
- Step 3. Use “For loop” to iterate upto the user inserted value.
- Step 4. The “For loop” will calculate the sum of the user inserted value.
- Step 5. Stop
Let’s try and understand it better using the Image given below.
C Program for Sum Of N Natural Numbers
#include <stdio.h>
int main()
{
//for initialize variable
int Number, i, Sum = 0;
//to take user input
printf ("\n Kindly Insert an Integer Variable\n");
scanf ("%d", &Number);
//use for loop for these condition
for(i = 1; i <= Number; i++)
{
Sum = Sum + i;
}
//display
printf ("Sum of Natural Numbers = %d", Sum);
return 0;
}
Output
Kindly Insert an Integer Variable : 3 Sum of Natural Numbers = 6
Getting Started
- ASCII Table
- Positive or Negative number: C | C++ | Java | Python
- Even or Odd number: C | C++ | Java | Python
- Sum of First N Natural numbers: C | C++ | Java | Python
- Sum of N natural numbers: C | C++ | Java | Python
- Sum of numbers in a given range: C | C++ | Java | Python
- Greatest of two numbers: C | C++ | Java | Python
- Greatest of the Three numbers: C | C++ | Java | Python
- Leap year or not: C | C++ | Java | Python
- Prime number: C | C++ | Java | Python
- Prime number within a given range: C | C++ | Java | Python
- Sum of digits of a number: C | C++ | Java | Python
- Reverse of a number : C | C++ | Java | Python
- Palindrome number: C | C++ | Java | Python
- Armstrong number : C | C++ | Java | Python
- Armstrong number in a given range : C | C++ | Java | Python
- Fibonacci Series upto nth term : C | C++ | Java | Python
- Find the Nth Term of the Fibonacci Series : C | C++ | Java | Python
- Factorial of a number : C | C++ | Java | Python
- Power of a number : C | C++ | Java | Python
- Factor of a number : C | C++ | Java | Python
- Finding Prime Factors of a number : C | C++ | Java | Python
- Strong number : C | C++ | Java | Python
- Perfect number : C | C++ | Java | Python
- Automorphic number : C | C++ | Java | Python
- Harshad number : C | C++ | Java | Python
- Abundant number : C| C++ | Java | Python
- Friendly pair : C | C++ | Java | Python

Login/Signup to comment