急急急!!!关于C语言的智力题。
发布网友
发布时间:2022-07-11 21:56
我来回答
共3个回答
热心网友
时间:2023-11-06 15:10
#include <conio.h>
void main()
{
unsigned short int i,k;
char j=1;
start: clrscr();
printf("\nPlease input one piece.(unsigned short int)\n");
scanf("%u",&i);
printf("\nPlease guess one piece.(unsigned short int)\n");
scanf("%u",&k);
while ( j )
{
if(k==i)
{
printf("\nYou are right.\n");
j=0;
goto l1;
}
printf("\nYou are WRONG.\n");
if (k>i)
printf("\nYou of number is big.\n");
else
printf("\nYou of number is small.\n");
printf("\nPlease contiun to input.\n");
scanf("%u",&k);
l1: ;
}
printf("\nAre you again?(YES input 1. NO input 0.)\n");
scanf("%u",&k);
j=1;
if(k) goto start;
}
热心网友
时间:2023-11-06 15:11
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main ()
{
loop:
int x,y,i=1;
srand((unsigned)time(NULL));
x=rand()%100+1;
while (i<=10)
{
printf ("请输入:");
scanf ("%d",&y);
if (x==y) {printf ("对了!你用了%d次。\n",i);break;}
if (y>x) printf ("大了!\n");else printf ("小了!\n");
i++;
}
if (i>10)printf ("正确数是:%d\n",x);
goto loop;
}
热心网友
时间:2023-11-06 15:11
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int g,i;
srand(time(NULL));
g=rand();
do
{
printf("Input a Number:");
scanf("%d",&i);
if (i!=g) printf("WRONG,%s",i>g?"Too Big":"Too Small");
}while(i!=g);
printf("RIGHT\n");
return 0;
}