Problem-16
215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
What is the sum of the digits of the number 21000?
Solution
#include<iostream> using namespace std; int main() { int *arr=new int[1000]; long long int i,N=1000,sum=0; arr[0]=1; for(i=1;i<1000;i++) arr[i]=0; while(N--) { for(i=0;i<1000;i++) arr[i]=arr[i]*2; for(i=0;i<1000;i++) { arr[i+1]+=arr[i]/10; arr[i]=arr[i]%10; } } for(int i=0;i<1000;i++) cout<<arr[i]; for(int i=0;i<1000;i++) sum+=arr[i]; cout<<sum; return 0; }
No comments:
Post a Comment