#include
#include
#define MAX 10
void trans(int d, char b[])
{
char st[MAX];
char ch;
int i = 0;
int top = -1;
while (d != 0)
{
ch ='0'+d % 2;
top++;
st[top] = ch;
d / 2;
}
while (top != -1)
{
b[i] = st[top];
top--;
i++;
}
b[i] = '\0';
}
void main()
{
int n;
char str[MAX];
//scanf("%d", &n);
do
{
scanf("%d", &n);
} while (n < 0);
trans(n, str);
printf("对应的二进制数:%s\n", str);
system("pause");
}
这是10转2进制的程序,为什么出现Access violation的错误啊,还有ch ='0'+d % 2;这语句中为什么要加一个'0'啊,求大神解释?