Added source.
This commit is contained in:
parent
10d897d6d2
commit
19b7d28b12
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
# Ignore binaries
|
||||
bin/
|
25
Makefile
Normal file
25
Makefile
Normal file
@ -0,0 +1,25 @@
|
||||
CXX=gcc
|
||||
CXXFLAGS= -O3 -Wall -std=gnu99
|
||||
|
||||
INCLUDES=
|
||||
LIBS=
|
||||
|
||||
MV=mv
|
||||
MKDIR=mkdir -p
|
||||
RM=rm -rf
|
||||
|
||||
SRC_FILES := $(wildcard src/*.c)
|
||||
OBJ_FILES := $(addprefix src/, $(notdir $(SRC_FILES:.c=.o)))
|
||||
|
||||
all: $(OBJ_FILES)
|
||||
$(MKDIR) bin
|
||||
$(CXX) $(CXXFLAGS) $(LIBS) -o bin/cointoss src/*.o
|
||||
|
||||
src/%.o: src/%.c
|
||||
$(CXX) $(CXXFLAGS) $(INCLUDES) -c -o $@ $<
|
||||
|
||||
clean:
|
||||
$(RM) src/*.o
|
||||
|
||||
fullclean: clean
|
||||
$(RM) bin
|
30
src/main.c
Normal file
30
src/main.c
Normal file
@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
char version[7] = "v0.1";
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
printf("Welcome to Coin Toss %s\n", version);
|
||||
if(argc < 2 || argc > 3) {
|
||||
printf("Usage: %s [trials]\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int trials = atoi(argv[1]);
|
||||
int heads = 0;
|
||||
int tails = 0;
|
||||
|
||||
srand(time(NULL));
|
||||
|
||||
for(int i = 0; i < trials; i++) {
|
||||
int r = rand() % 100 + 1;
|
||||
if(r <= 50) heads++;
|
||||
else tails++;
|
||||
}
|
||||
|
||||
printf("Done.\n");
|
||||
printf("Heads: %i\n", heads);
|
||||
printf("Tails: %i\n", tails);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user