#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>
float rnd(){
return rand()/(float) RAND_MAX;
}
int main(){
srand(2);
printf("float = %f" , rnd());
return 0;
}
猜数字游戏
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "mylibs.h"
int rnd1();
int main() {
srand((unsigned int)time(NULL));
int generate_number = rnd1();
int guess_number;
while (1){
printf("please input a number\n");
scanf("%d", &guess_number);
if (guess_number > generate_number){
printf("too large\n");
} else if(guess_number < generate_number){
printf("too small\n");
}else{
printf("right ! \n");
break;
}
}
return 0;
}
|