编程笔记
-
猜一下矩阵中的数字
#include <stdio.h> #include <stdlib.h> #include <time.h> int random(int m, int n); int main() {// int try1, maxTries, numProblems, answer, response; int num1, num2; numProblems = 5;…
-
猜一个1到100之间的数字
#include <stdio.h> #include <stdlib.h> #include <time.h> int main() {// int answer, guess, random(int, int); printf("Guess a number from 1 to 100./n"); srand(time (0)); an…
-
掷两个骰子并呈现总数,然后要求用户猜测下一个总数
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <ctype.h> int main() { int dice1, dice2; int total1, total2; time_t t; char ans; sr…
-
生成随机数
#include <stdio.h> #include <stdlib.h> int main() { int iRandomNum = 0; int iResponse = 0; iRandomNum = (rand() % 10) + 1; printf("/nGuess a number between 1 and 10: "); scanf(&…
-
使用if语句猜一个随机数
以下程序包含if的示例。它使用标准随机数生成器rand()生成幻数,它返回0到RAND_MAX之间的任意数字。 RAND_MAX定义一个32,767或更大的整数值。 rand()函数需要头文件<stdlib.h>。 #include <stdio.h> #i…
-
使用if ... else语句猜一个随机数
#include <stdio.h> #include <stdlib.h> int main(void) { int magic; /* magic number */ int guess; /* user's guess */ magic = rand(); /* generate the magic number */ printf("Guess …
-
使用嵌套if ... else语句猜一个随机数
#include <stdio.h> #include <stdlib.h> int main(void) { int magic; /* magic number */ int guess; /* user's guess */ magic = rand(); /* get a random number */ printf("Guess the ma…
-
使用if -else-if语句猜一个随机数
#include <stdio.h> #include <stdlib.h> int main(void) { int magic; /* magic number */ int guess; /* user's guess */ magic = rand(); /* generate the magic number */ printf("Guess …
-
使用seedrnd()重置随机数生成器并生成更多随机数
#include <stdio.h> #include <stdlib.h> int rnd(void); void seedrnd(void); int main() { int x; seedrnd(); puts("Behold! 20 Random Numbers!"); for(x=0;x<0;x++) printf("%d/…
-
使seedrnd()函数使用当前时间为随机数生成器种子
#include <stdio.h> #include <stdlib.h> #include <time.h> int rnd(void); void seedrnd(void); int main() { int x; seedrnd(); puts("Behold! 100 Random Numbers!"); for(x=0;x&l…