Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unistd.h>
- #include <pthread.h>
- #include <stdio.h>
- #include <stdlib.h>
- #define SIZE 9
- struct Symbol
- {
- int n, k;
- };
- unsigned long long newton(int n, int long k)
- {
- if (k == 0 || k == n)
- return 1;
- if (k > 0 && k < n)
- return newton(n - 1, k - 1) + newton(n - 1, k);
- return 0;
- }
- void *funkcja1(void *args) {
- struct Symbol *s = (struct Symbol*) args;
- unsigned long long wynik = newton(s->n, s->k);
- pthread_exit((void *)wynik);
- }
- void *funkcja2(void *args) {
- char *imie = (char *)args;
- int i = 0;
- while (1)
- {
- printf("%c", imie[i]);
- fflush(stdout);
- if (i >= SIZE)
- i = 0;
- else
- i++;
- usleep(1000 * 300);
- }
- phtread_exit(NULL);
- }
- int main()
- {
- int n, k;
- const char *imie = "Arkadiusz";
- printf("Podaj n: ");
- scanf("%d", &n);
- printf("Podaj k: ");
- scanf("%d", &k);
- struct Symbol *sym = (struct Symbol *)malloc(sizeof(struct Symbol));
- sym->n = n;
- sym->k = k;
- pthread_t thread1, thread2;
- void *wynik;
- pthread_create(&thread1, NULL, funkcja1, (void *)sym);
- pthread_create(&thread2, NULL, funkcja2, (void *)imie);
- pthread_join(thread1, &wynik);
- pthread_cancel(thread2);
- printf("\nWynik: %llu\n", (unsigned long long)wynik);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement