编写main,测试函数itos的正确性


#include
char str[100];
void itos(int n);
int main()
{
    int m;

    void itos(m);
    return 0;
}
void itos(int n)
{

    printf("请输入整型数据:");
    scanf("%d",&n);

    int a[100]= {n};
    int top=0;
    int i=0;
    while(n)
    {
        a[top++]=n%10;
        n=n/10;
    }
    while(top)
    {
        str[i++]=a[--top]+'0';
    }
}

仅供参考,望采纳~


#include<stdio.h>
char str[100];
void itos(int n);
int main()
{
    int m;
    itos(m);
    printf("%s\n",str);
    return 0;
}
void itos(int n)
{

    printf("请输入整型数据:");
    scanf("%d",&n);

    int a[100]= {n};
    int top=0;
    int i=0;
    while(n)
    {
        a[top++]=n%10;
        n=n/10;
    }
    while(top)
    {
        str[i++]=a[--top]+'0';
    }
}

img


正确性:看结果感觉是对的