











C Program for Sum Of N Natural Numbers


Find Sum of N Natural Numbers
In the C programming language, the user is allowed to insert any integer value. With the help of For loop, this C program can calculate the sum of N natural numbers. Within this program, first printf statement will request the user to insert a number or value then the scanf statement will allocate the user inserted value to integer variable. The sum is calculated in the For loop.
To perform the arithmetic operation of addition of n numbers we use this conditions
Example –
Enter Number 3
N natural numbers 1,2,3,4,5,6,7,8…….
Where first 3 number is 1,2,3
Then we will return sum of number = 6
Working
- 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
C Code
/* C Program to find Sum of N Numbers using For Loop */
#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 : 5
Sum of Natural Numbers = 15
- Positive or Negative number: C | C++ | Java
- Even or Odd number: C | C++ | Java
- Sum of First N Natural numbers: C | C++ | Java
- Sum of N natural numbers: C | C++ | Java
- Sum of numbers in a given range: C | C++ | Java
- Greatest of two numbers: C | C++ | Java
- Greatest of the Three numbers: C | C++ | Java
- Leap year or not: C | C++ | Java
- Prime number: C | C++ | Java
- Prime number within a given range: C | C++ | Java
- Factorial of a number: C | C++ | Java
- Sum of digits of a number: C | C++ | Java
- Reverse of a number : C | C++ | Java
- Palindrome number: C | C++ | Java
- Armstrong number : C | C++ | Java
- Armstrong number in a given range : C | C++ | Java
- Fibonacci Series upto nth term : C | C++ | Java
- Factorial of a number : C | C++ | Java
- Power of a number : C | C++ | Java
- Factor of a number : C | C++ | Java
- Strong number : C | C++ | Java
- Perfect number : C | C++ | Java
- Automorphic number : C | C++ | Java
- Harshad number : C | C++ | Java
- Abundant number : C| C++ | Java
- Friendly pair : C | C++ | Java


Login/Signup to comment