Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
7oSkaaa committed Apr 26, 2023
2 parents 9ce25c8 + 19eecc4 commit 5fe2ad8
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions 04- April/26- Add Digits/26- Add Digits (Ibrahim Khalid).cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// author : Ibrahim Khalid
class Solution {
public:
int addDigits(int num) {
// str to convert num(int) to string to can count digits
string str=to_string(num);
int sum;
// if Digitalis number equal 1 break from loop
while(str.size()!=1){
sum=0;
// to summation digits
for(int i=0;i<str.size();i++){
//to convert from char to int
sum+=(str[i]-'0');
}
// to convert summation to string to check digitalis number
str=to_string(sum);

}
return sum;
}
};

0 comments on commit 5fe2ad8

Please sign in to comment.