Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - C Cheng. Read an integer from the keyboard, convert it into a string and output it.

For example: input 123, it will be converted into the string "123"

C Cheng. Read an integer from the keyboard, convert it into a string and output it.

For example: input 123, it will be converted into the string "123"

#include

void dtoc(long a, char str[]);

int main()

{

long intg;

char istr[20];

for(int i=0; i<20; i++)

< p> istr[i] = '\0';

printf("Please input a long integer:");

scanf("%d", &intg);

dtoc(intg, istr);

printf("%s\n", istr);

return 0;

}< /p>

void dtoc(long a, char str[])

{

static int t=0;

if(a > 0 )

{

dtoc(a/10, str);

str[t++] = a%10 + '0';

< p> }

else if(a == 0)

{

str[t] = '0';

return ;

}

else

{

str[t++] = '-';;

a = -a;

dtoc(a, str);

}

}