C Program to Find the Sum of first 10 Natural Numbers
In this article, we are going to write a c program to find the Sum of first 10 Natural Numbers
We will make this program in the following way -:
- C Program to Find the Sum of first 10 Natural Numbers Using For Loop
- C Program to Find the Sum of first 10 Natural Numbers Using While Loop
- C Program to Find the Sum of first 10 Natural Numbers Using Do While Loop
- C Program to Find the Sum of first 10 Natural Numbers Using Array
- C Program to Find the Sum of first 10 Natural Numbers Using Function
- C Program to Find the Sum of first 10 Natural Numbers Using Recursion
Let’s understand all these methods one by one
C Program to Find the Sum of first 10 Natural Numbers Using For Loop
To make this program, you must first know about the loop because we are going to use the concept of loop to make this program.
There are mainly three types of loops –: While Loop, Do While Loop, and For Loop.
You can read about the loop in detail here -:
Here we are going to make this program with the help of these three types of loops.
Let’s first make this program with the help of simple loop (For Loop)
Algorithm
- Program Start
- Declaration of Variable
- Calculating Sum of 1st 10 Naturals Numbers
- Displaying the Sum first 10 Naturals Numbers
- Program End
Program
//C Program to Find the Sum of first 10 Natural Numbers Using For loop
#include<stdio.h>
void main()
{
//Declaring Variable
int i, sum = 0;
for(i=1;i<=10;i++)
{
sum = sum + i;
}
printf("\nSum of first 10 Natural Numbers is : %d", sum);
}
Output
Sum of first 10 Natural Numbers is : 55
C Program to Find the Sum of first 10 Natural Numbers Using While Loop
Program
//C Program to Find the Sum of first 10 Natural Numbers Using While loop
#include<stdio.h>
void main()
{
//Declaring Variable
int i=1, sum = 0;
//Calculating Sum
while(i<=10)
{
sum = sum + i;
i++;
}
printf("\nSum of first 10 Natural Numbers is : %d", sum);
}
Output
Sum of first 10 Natural Numbers is : 55
C Program to Find the Sum of first 10 Natural Numbers Using Do While Loop
Program
//C Program to Find the Sum of first 10 Natural Numbers Using While loop
#include<stdio.h>
int main()
{
//Declaring Variable
int i=1, sum = 0;
do
{
sum = sum + i;
i++;
}while(i<=10);
printf("\nSum of first 10 Natural Numbers is : %d", sum);
return 0;
}
Output
Sum of first 10 Natural Numbers is : 55
C Program to Find the Sum of first 10 Natural Numbers Using Array
Program
//C Program to Find the Sum of first 10 Natural Numbers Using Array
#include<stdio.h>
void main()
{
//Declaring Variable
int i, sum = 0 , a[10]= {1,2,3,4,5,6,7,8,9,10};
//Calculating Sum
for(i=0;i<10;i++)
{
sum = sum + a[i];
}
//printing Sum
printf("\nSum of first 10 Natural Numbers is : %d", sum);
}
Output
Sum of first 10 Natural Numbers is : 55
C Program to Find the Sum of first 10 Natural Numbers Using Function
Program
//C Program to Find the Sum of first 10 Natural Numbers Using Function
#include<stdio.h>
int sum();
int main()
{
//Declaring Variable
int s;
s =sum();
printf("\nSum of first 10 Natural Numbers is : %d", s);
return 0;
}
int sum()
{
int i, sum = 0;
for(i=1;i<=10;i++)
{
sum = sum + i;
}
return (sum);
}
Output
Sum of first 10 Natural Numbers is : 55
C Program to Find the Sum of first 10 Natural Numbers Using Recursion
Program
//C Program to Find the Sum of 1st 10 Natural Numbers Using Recursion
#include<stdio.h>
int sum();
int main()
{
//variable declaration
int s;
s=sum(10); //Calling Recursive Function
printf("\nSum of first 10 Natural Numbers is : %d", s);
return 0;
}
int sum(int n)
{
int s=0;
if(n==1)
return (n);
s = n + sum(n-1);
return (s);
}
Output
Sum of first 10 Natural Numbers is : 55
Read More
- Download C Language Notes Pdf
- C Language Tutorial For Beginners
- C Programming Examples With Output
- 250+ C Programs for Practice PDF Free Download
Conclusion
So friends, in this article, we have written a c program to calculate the sum first 10 natural numbers in 6 different ways.
- C Program to Find the Sum of first 10 Natural Numbers Using For Loop
- C Program to Find the Sum of first 10 Natural Numbers Using While Loop
- C Program to Find the Sum of first 10 Natural Numbers Using Do While Loop
- C Program to Find the Sum of first 10 Natural Numbers Using Array
- C Program to Find the Sum of first 10 Natural Numbers Using Function
- C Program to Find the Sum of first 10 Natural Numbers Using Recursion
If you have difficulty to understanding any program or have any doubts or questions, then tell me in the comment below.