當前位置:編程學習大全網 - 編程軟體 - C程。從鍵盤上讀入壹個整型數,將其轉化成字符串並輸出。例如:輸入123,則轉換為字符串“123”

C程。從鍵盤上讀入壹個整型數,將其轉化成字符串並輸出。例如:輸入123,則轉換為字符串“123”

#include <stdio.h>

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

int main()

{

long intg;

char istr[20];

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

istr[i] = '\0';

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

scanf("%d", &intg);

dtoc(intg, istr);

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

return 0;

}

void dtoc(long a, char str[])

{

static int t=0;

if(a > 0)

{

dtoc(a/10, str);

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

}

else if(a == 0)

{

str[t] = '0';

return;

}

else

{

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

a = -a;

dtoc(a, str);

}

}

  • 上一篇:水利水電工程施工掘進機開挖隧洞軸線上下偏移該如何預防?
  • 下一篇:闞怎麽讀組詞
  • copyright 2024編程學習大全網