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
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
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;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us