Thursday, 3 July 2014

Value of 2 power 1000 to calculate sum of digits

/*ignore the special characters at the end of the answer result=1366*/
main()
{
char c[560];
int k=0;
while(k<=559)
{
c[k]='0';
k++;
}
c[559]='2';
int n=1;
while(n<=999)
{
    k=0;
while(k<=559)
{
   c[k]=(c[k]*2)-48;
   k++;
}
k=0;
while(k<=559)
{
    if(c[k]>57){ c[k-1]+=1;c[k]-=10;   }
k++;
}
if(c[0]>57)
{
k=0;
while(k<=559)
{
   c[k]=c[k]/2;
   k++;
}
    printf("%s",c);
    exit(0);
}
n++;
}
printf("%s",c);
}

No comments:

Post a Comment