mirror of
https://github.com/tiennm99/HDH.git
synced 2026-06-09 06:13:08 +00:00
Update
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
all: ex1.o ex2.o
|
||||
gcc ex1.o -o ex1 -lgmp
|
||||
gcc ex2.o -o ex2
|
||||
ex1.o: ex1.c
|
||||
gcc -c ex1.c
|
||||
ex2.o: ex2.c
|
||||
gcc -c ex2.c
|
||||
clean:
|
||||
rm -f *.o ex1 ex2
|
||||
Binary file not shown.
+84
@@ -0,0 +1,84 @@
|
||||
#include <gmp.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define FILE_NAME "numbers.txt"
|
||||
#define MAX_SIZE 10
|
||||
|
||||
mpz_t array[MAX_SIZE];
|
||||
int size = 0;
|
||||
|
||||
void readfile() {
|
||||
FILE *file;
|
||||
char str[80];
|
||||
mpz_t temp;
|
||||
mpz_init(temp);
|
||||
file = fopen(FILE_NAME, "r");
|
||||
if (file == NULL) {
|
||||
perror("Can't open file!\n");
|
||||
exit(1);
|
||||
}
|
||||
while (1) {
|
||||
fgets(str, 80, file);
|
||||
if (feof(file)) {
|
||||
break;
|
||||
}
|
||||
if (mpz_set_str(temp, str, 10)) {
|
||||
perror("Error! Not a number");
|
||||
exit(1);
|
||||
}
|
||||
mpz_set(array[size++], temp);
|
||||
}
|
||||
mpz_clear(temp);
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
void count(int n) {
|
||||
int count = 0;
|
||||
mpz_t temp;
|
||||
mpz_init(temp);
|
||||
for (int i = 0; i < size; ++i) {
|
||||
mpz_mod_ui(temp, array[i], n);
|
||||
if (!mpz_cmp_ui(temp, 0)) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
printf("Co %d so chia het cho %d.\n", count, n);
|
||||
mpz_clear(temp);
|
||||
}
|
||||
|
||||
int main() {
|
||||
int child1_pid = 0,
|
||||
child2_pid = 0,
|
||||
child3_pid = 0,
|
||||
parrent_pid = getpid();
|
||||
readfile();
|
||||
child1_pid = fork();
|
||||
if (child1_pid < 0) {
|
||||
perror("Error at 1st pork()!\n");
|
||||
exit(1);
|
||||
} else if (child1_pid == 0) {
|
||||
count(2);
|
||||
}
|
||||
if (parrent_pid == getpid()) {
|
||||
child2_pid = fork();
|
||||
if (child2_pid < 0) {
|
||||
perror("Error at 2nd pork()!\n");
|
||||
exit(1);
|
||||
} else if (child2_pid == 0) {
|
||||
count(3);
|
||||
}
|
||||
}
|
||||
if (parrent_pid == getpid()) {
|
||||
child3_pid = fork();
|
||||
if (child3_pid < 0) {
|
||||
perror("Error at 3rd pork()!\n");
|
||||
exit(1);
|
||||
} else if (child3_pid == 0) {
|
||||
count(5);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,9 @@
|
||||
12918237493729473291790579217597
|
||||
4213412542666666666666665
|
||||
321456765
|
||||
4432524352352365
|
||||
106235754869
|
||||
11356243645879870
|
||||
345943809680943809584352245
|
||||
jweois
|
||||
209345790jdsljflks
|
||||
Reference in New Issue
Block a user