#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
int main()
{
long int n,i,sum,num,b;
char s[100];
while(gets(s))
{
sum=0;
n=strlen(s);
for(i=0;i<n;i++)
{
num=s[i]-'0';
b=num*(pow(2,n-i)-1);
sum=sum+b;
}
if(sum==0) break;
printf("%ld\n",sum);
}
return 0;
}
num=s[i]-'0';
ReplyDeleteI didn't understand this line?..why you have to do minus 0?..:/
to convert character to digit.
Deletesay, char ch = '5';
then, int value = ch-'0' will make it calculable.
ch+95 won't create 100, but value+95 will be 100.
thanks a lot
Delete