SERIES
Series:
Here we will discuss the problems related to series.
A number of related events or things following each other is called series.
Program to find the sum of n natural numbers.
#include<stdio.h>
int main()
{
int n,s_n;
printf("Enter the highest value of natural numbers you need to add\n");
scanf("%d",&n);
s_n = sumOfNaturalNumbers(n);
printf("The sum %d natural numbers is equal to %d",n,s_n);
return 0;
}
int sumOfNaturalNumbers(int k)
{
k = k*(k+1)/2;
return k;
}
output:
Enter the highest value of natural numbers you need to add
5
The sum 5 natural numbers is equal to 15
Comments
Post a Comment