2022年6月23日 星期四

random seed

 #include <stdio.h>

#include <stdlib.h>

#include <time.h>//刮數seed會用到 

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[])

{

int answer=rand()%100;//random會用到標準含函數庫 

srand(time(0));

int guess;

do

{

scanf("%d",&guess);

if(guess>answer)

{

printf("too large\n");

}

else if(guess<answer)

{

printf("too small\n");

}

else 

{

printf("correct\n");

}

}

while(guess != answer);//因為你不知猜幾次,所以用do while前測 

return 0;

}

沒有留言:

張貼留言

algorithm

 #include <iostream> #include <string.h> using namespace std; int main(int argc, char** argv)  { for(int j=2;j<=100;j++)//j...