就是这段代码,到vc中就运行不了,
#include <math.h>
#include <stdio.h>
void main(void)
{
int answer[4]={1,3,5,2},guess,a,b,times=0,i,j;
//初始化被猜答案为1352
printf("Please input the guess number:\n");
while (a != 4)
//进入猜数字的循环
{
a = 0;
b = 0;
//每次猜测之前设定A,B都为0
times++;
//猜测次数加1
printf("第%d次猜测",times);
scanf("%d",&guess);
//从键盘读取猜的四位数字
for (i = 3;i > -1;i--)
{
for (j = 0;j< 4; j++)
//进入猜测和正确答案比对循环
{
if ((int)(guess/pow10(i)) == answer[j])
//将每一位猜测数字比对
pow10(i)是去10的i次方
{
if(i + j == 3)
a = a+1;
//如果位置相同,a就加1
else
b=b+1;
//如果位置不同,b就加1
}
}
guess=guess-(int)(guess/pow10(i))*pow10(i);
//比对下一个猜测数字
}
printf("%d A %d B\n",a,b);
//显示本次猜测的A,B正确性
}
}