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

RESTful APIs with CRUD Operations in Laravel 12| (2025)

  RESTful APIs serve as the foundation of modern web development. They follow a set of rules called Representational State Transfer (REST) t...

Powered by Blogger.