Hi,everyone .When I try to change decimal number into other type numbers.
I write it like as follow:
int main()
{
int integer;
int a[100] = {0};
static double account = 0;
int i ;
double ii = 0;
double number = 0;
double digit;
printf("Enter one decimal number");
scanf("%d",&integer);
printf("Enter one number as digit you want to change to");
scanf("%lf",&digit);
while (number <= integer)
{
number = pow(digit, account);
account += 1;
}
for(i = account;i >= 0;i--)
{
ii = i;
a[i] = integer / pow(digit, ii);
integer = integer - pow(digit, ii) * a[i];
}
printf("\n%d",account); //I am puzzled here
printf("\nThe %.0f number you need is ", digit);
for(i = (account - 2);i >= 0;i--)
{
if (a[i] == 10)
printf("A");
else if (a[i] == 11)
printf("B");
else if (a[i] == 12)
printf("C");
else if (a[i] == 13)
printf("D");
else if (a[i] == 14)
printf("E");
else if (a[i] == 15)
printf("F");
if ((a[i] == 10)||(a[i] == 11)||(a[i] == 12)
||(a[i] == 13)||(a[i] == 14)||(a[i] == 15))
continue;
printf("%d", a[i]);
}
return 0;
}
But I am puzzled by the VALUE of account .I print it after the first while
loop , but its value still keeps as 0.I think it should be some number != 0
And if I want to print the result I have to initialize i as (account - 2)
,otherwise
it will print two 0 before the right answer .Why ?
---------------------------------
@yahoo.cn 新域名、无限量,快来抢注!
[Non-text portions of this message have been removed]