Codeforces 102B. Sum of Digits Solution

  1. Solution IN c++:

  2. ///**********ALLAH IS ALMIGHTY************///
  3. ///AH Tonmoy
  4. ///Department of CSE,23rd batch
  5. ///Islamic University,Bangladesh
  6. #include<bits/stdc++.h>
  7. using namespace std;
  8. int main()
  9. {
  10. int sum = 0,i,c=0;
  11. string s;
  12. cin>>s;
  13. {
  14. c=0;
  15. while(s.length()>1)
  16. {
  17. sum=0;
  18. for(i=0; i<s.length(); i++)
  19. {
  20. sum=sum+(s[i]-'0');
  21. }
  22. s=to_string(sum);
  23. c++;
  24. }
  25. cout<<c<<endl;
  26. }
  27.  
  28. }

1 comment:

  1. what is this line mean---

    to_string (sum) .. what the hell is this (to_string)

    ReplyDelete

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.