fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. int main ()
  5. {
  6. int num;
  7. std::cin >> num;
  8. double n = pow(2, num); /* note I use just double */
  9.  
  10. std::string nstr = std::to_string(n);
  11. const char* nstr_p = nstr.c_str();
  12.  
  13. std::cout << std::fixed << nstr << std::endl;
  14. int sum = 0;
  15. while (std::isdigit(*nstr_p)) /* number contains dot and fractional (.0000) */
  16. {
  17. sum = sum + (*nstr_p - '0'); /* convert character to integer and sum it */
  18. nstr_p++;
  19. }
  20. std::cout << sum << std::endl;
  21. }
Success #stdin #stdout 0s 16064KB
stdin
1000
stdout
10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376.000000
1366