?? guess.c
字號:
#include <math.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <process.h>
#include <windows.h>
void main(void)
{
int answer[4];
int guess;
int a=0, b=0;
int i=0, j=0;
int times=0;
char temp='Y';
// printf("DO you want to continue?(Y\N)");
// temp = getchar();
while ((temp == 'Y')||(temp == 'y'))
{
times = 0;
a=0, b=0;
for (i=0; i<=3; i++)
{
srand( (unsigned)time( NULL ) );
answer[i] = rand() % 10;
for (j=0; j<i; j++)
{
while (answer[i] == answer[j])
{
answer[i] = rand() % 10;
j = -1;
}
}
}
printf("Please guess!\n");
while (a!=4)
{
a = 0;
b = 0;
times++;
do{
printf("%d ", times);
scanf("%d", &guess);
if (guess == 0)
exit(0);
}while(guess<0 || guess>9999);
for (i=3; i>-1; i--)
{
for (j=0; j<4; j++)
{
if ((int)(guess/pow(10,i)) == answer[j])
{
if (i+j==3)
a++;
else b++;
}
}
guess = guess - (int)(guess/pow(10,i)) * pow(10, i);
}
printf(" %dA%dB\n", a, b);
}
getchar();
printf("DO you want to continue?(Y/N)\n");
temp = getchar();
getchar();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -