chapter5
This commit is contained in:
parent
50a27f1d6c
commit
5bcb1746fe
20
DeitelC/Chapter5/coinTossing.c
Normal file
20
DeitelC/Chapter5/coinTossing.c
Normal file
@ -0,0 +1,20 @@
|
||||
#include <stdio.h>
|
||||
#include "flip.h"
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
|
||||
srand(time(NULL));
|
||||
|
||||
int heads = 0, tails = 0;
|
||||
for(int i = 0; i < 100; i++){
|
||||
if(flip()) {
|
||||
heads++;
|
||||
} else {
|
||||
tails++;
|
||||
}
|
||||
}
|
||||
printf("%s%d%s%d\n", "Heads: ", heads, ", Tails: ", tails);
|
||||
return 0;
|
||||
}
|
6
DeitelC/Chapter5/flip.c
Normal file
6
DeitelC/Chapter5/flip.c
Normal file
@ -0,0 +1,6 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
int flip() {
|
||||
return rand() % 2;
|
||||
}
|
6
DeitelC/Chapter5/flip.h
Normal file
6
DeitelC/Chapter5/flip.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef FLIP_H
|
||||
#define FLIP_H
|
||||
|
||||
int flip();
|
||||
|
||||
#endif
|
19
DeitelC/Chapter5/guessTheNum.c
Normal file
19
DeitelC/Chapter5/guessTheNum.c
Normal file
@ -0,0 +1,19 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
int main(void) {
|
||||
srand(time(NULL));
|
||||
int num = 1 + rand() % 999;
|
||||
printf("%s\n%s\n%s\n", "I have a number between 1 and 1000.", "Can you guess my number?", "Please type your first guess.");
|
||||
int scanNum = 0;
|
||||
scanf("%d", &scanNum);
|
||||
|
||||
if((scanNum > 1001) || (scanNum < 0)) {
|
||||
puts("Invalid integer!");
|
||||
}
|
||||
|
||||
while(scanNum != num) {
|
||||
if("")
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user