第1个回答 2008-01-17
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void main(void)
{
int num,guess;
srand((unsigned int)time(NULL));
num=rand()%500;
printf("%d\n",num);
do
{
printf("please input the number you guess:");
scanf("%d",&guess);
if(guess>num)
printf("The number you guess is larger than the guessed number!\n");
else if(guess<num)
printf("The number you guess is smaller than the guessed number!\n");
}while(num!=guess);
printf("Your guess is right!Congratulations!");
system("Pause");
}
第2个回答 2008-01-17
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int a:
a = srand((unsigned) time(&t)) % 10;
//产生0到9的随机数
估计你就不会在这,现在这个程序简单了
第3个回答 2008-01-17
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void main()
{
int i,g,j=1;
long t;
srand((unsigned)time(NULL));
i = rand() % 100;
printf("请输入您猜的数字(1-100):");
scanf("%d",&g);
t=time(NULL);
while(g!=i)
{
if(g>i)printf("\n您猜的数字大了。请重输入:");
if(g<i)printf("\n您猜的数字小了。请重输入:");
scanf("%d",&g);
j++;
}
t=time(NULL)-t;
printf("\n恭喜您!回答正确。你猜了%d次,用时%d秒。\n",j,t);
}
第4个回答 2008-01-17
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include <sys/timeb.h>
int ra(int b)
{
int a ;
int i;
a = rand()%100;
for( i = 0; i < 5 ;i++)
{
printf("Please input a number(0-100):\n");
scanf("%d",&b);
if(a == b)
{
printf("Bingo!\n");
printf("Answer is:%d",a);
break;
}else if( a > b)
{
printf("Less!\n");
}else if( a < b)
{
printf("More!\n");
}
if( i == 4)
{
printf("Game Overt!\n");
printf("Answer is:%d",a);
break;
}
}
return a;
}
void main()
{
timeb timebuf;
ftime(&timebuf);
time_t tm(timebuf.time);
srand(tm);
int c = 0 ;
ra(c);
getchar();
getchar();
}
第5个回答 2008-01-17
自己好好练练吧,不错的题目。