Answers for "how to find n numbers whoes sum is given"

1

Determine the sum of al digits of n

def sum_of_digits(n): 
	sum = 0
	while (n != 0): 
		sum = sum + int(n % 10) 
		n = int(n/10) 
	return sum
Posted by: Guest on October-20-2020
0

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

Code answers related to "how to find n numbers whoes sum is given"

Python Answers by Framework

Browse Popular Code Answers by Language