Skip to content

Commit

Permalink
Create RECURSEDIGSUM.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Priyanshiguptaaa authored Nov 17, 2020
1 parent 3035562 commit 4420bc4
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Recursion_Backtracking/RECURSEDIGSUM.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
int super(long long int num)
{
if(num<=9)
{
return num;
}
long long int sum=0;
long long int m=0;

while(num!=0)
{

m=num%10;
sum=sum+m;
num=num/10;
}
return super(sum);
}

// Complete the superDigit function below.
int superDigit(string n, int k)
{
long long int sum=0;

for(int i=0; i<n.size(); i++)
{
sum += n[i] - '0';
}

return super(sum*k);

}

0 comments on commit 4420bc4

Please sign in to comment.