fork(1) download
  1. #include <stdio.h>
  2. #include <pthread.h>
  3.  
  4. void* factorial(void* arg) {
  5. int n = *(int*)arg;
  6. long long fact = 1;
  7.  
  8. for(int i = 1; i <= n; i++) {
  9. fact *= i;
  10. }
  11.  
  12. printf("Factorial of %d = %lld\n", n, fact);
  13. return NULL;
  14. }
  15.  
  16. int main() {
  17. pthread_t thread;
  18. int number;
  19.  
  20. printf("Enter a number: ");
  21. scanf("%d", &number);
  22.  
  23. pthread_create(&thread, NULL, factorial, &number);
  24. pthread_join(thread, NULL);
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Enter a number: Factorial of 21847 = 0