Answers for "sum of n natural numbers"

C++
1

sum of n natural numbers in python

# Sum of natural numbers up to num

num = 16

if num < 0:
   print("Enter a positive number")
else:
   sum = 0
   # use while loop to iterate until zero
   while(num > 0):
       sum += num
       num -= 1
   print("The sum is", sum)
Posted by: Guest on January-18-2021
1

sum of all n integers

Sum of n integers 1 + 2 + 3 + ... + n = n * (n + 1) / 2
Posted by: Guest on April-06-2021
1

sum of n natural numbers

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int sum=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		sum+=i;
	}
		cout<<sum<<" ";
	cout<<endl;
	return 0;
}
Posted by: Guest on June-06-2021
1

formula for sum of n numbers

Sum of the First n Natural Numbers. We prove the formula 1+ 2+ ... + n = n(n+1) / 2, for n a natural number
Posted by: Guest on December-20-2020
-1

sum of n natural numbers in c

int addNumbers(int n)
{
    int count, sum = 0;

    for(count=1; count <= n; count++)
    {
        sum = sum + count;
    }
  
    return sum;
}
Posted by: Guest on November-23-2020

Code answers related to "sum of n natural numbers"

Browse Popular Code Answers by Language