Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  6564
Language: C/C++
Code:
#include <stdio.h>
#include <math.h>
void main(void)
{
     int answer[4]={1,3,5,2},guess,a,b,times=0,i,j;//初始化被猜答案为1352
     printf("please guessn");
     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加1
               a=a+1;
               else
               b=b+1;
          }
     }
     printf("    %dA%dBn",a,b);//显示本次猜测的AB正确性
}
          
          
Comments: