#include <stdio.h>
#include <string.h>
#define MAX 100
void itoa(int n, char s[]);
void reverses(char s[]);
void
itoa(int n, char s[])
{
int i;
char sign;
if((sign = n) < 0)
n = -n;
i = 0;
do
{
s[i++] = n % 10 + '0';
}while((n /= 10) != 0);
if(sign < 0)
s[i++] = '-';
s[i] = '\0';
reverses(s);
}
void
reverses(char s[])
{
int temp;
int i, j;
for(i = 0, j = strlen(s)-1; i < j; i++, j--)
{
temp = s[i];
s[i] = s[j];
s[j] = temp;
}
}
int
main()
{
int num;
char s[MAX];
printf("please input a number:\n");
scanf("%d", &num);
itoa(num, s);
printf("%s\n", s);
return 0;
}
把任一数字转换为数字字符串输出
最新推荐文章于 2023-01-05 21:49:16 发布