Skip to content
Snippets Groups Projects
Commit a34fa21a authored by Kevin Lyda's avatar Kevin Lyda :speech_balloon:
Browse files

Initial version w/o timing or counters.

parents
Branches
No related tags found
No related merge requests found
cube-test
.*.swp
Makefile 0 → 100644
#
# Makefile
# Kevin Lyda, 2017-10-12 19:14
#
cube-test: cube-test.c
cc -Wall -o cube-test cube-test.c
# vim:ft=make
#
/*
* cube-test.c
* Copyright (C) 2017 Kevin Lyda <kevin@phrye.com>
*
* Distributed under terms of the GPL license.
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int
random_two_digit_number() {
return (rand() % 90) + 10;
}
int
cube(int n) {
return n * n * n;
}
int
read_number() {
char buf[10];
if (!fgets(buf, sizeof buf, stdin)) {
return 0;
}
return atoi(buf);
}
int
main(int argc, char *argv[]) {
int guess, number;
srand(time(NULL));
while (1) {
number = random_two_digit_number();
printf("Number is %d. Cube root (0 to exit)? ", cube(number));
guess = read_number();
if (guess == 0) {
exit(0);
}
if (guess == number) {
printf("Correct.\n");
} else {
printf("Not correct. Number was %d.\n", number);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment