diff options
author | Léo Gourdin <leo.gourdin@univ-grenoble-alpes.fr> | 2021-04-22 11:25:02 +0200 |
---|---|---|
committer | Léo Gourdin <leo.gourdin@univ-grenoble-alpes.fr> | 2021-04-22 11:25:02 +0200 |
commit | dff562c47c47fcac90c116782c92b692f2bb9bf9 (patch) | |
tree | 9325a0eea680b8f7f1256cbac3f93423ef23b9e7 /test/gourdinl/c/prime.c | |
parent | e37d655db0ec3d2c002e200c3e70a1997e39a458 (diff) | |
download | compcert-kvx-dff562c47c47fcac90c116782c92b692f2bb9bf9.tar.gz compcert-kvx-dff562c47c47fcac90c116782c92b692f2bb9bf9.zip |
moving my tests
Diffstat (limited to 'test/gourdinl/c/prime.c')
-rw-r--r-- | test/gourdinl/c/prime.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/gourdinl/c/prime.c b/test/gourdinl/c/prime.c new file mode 100644 index 00000000..6c51db32 --- /dev/null +++ b/test/gourdinl/c/prime.c @@ -0,0 +1,23 @@ +/* prime1.c It prompts the user to enter an integer N. It prints out + * if it is a prime or not. If not, it prints out a factor of N. + */ + +#include <stdio.h> + +int main(int n) { + int i; + int flag; + + flag = 1; + for (i=2; (i<(n/2)) && flag; ) { /* May be we do not need to test + values of i greater than the square root of n? */ + if ((n % i) == 0) /* If true n is divisible by i */ + flag = 0; + else + i++; + } + + if (flag) + return 1; + return 0; +} |