Advertisement
Aodai

Untitled

Feb 1st, 2021
927
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <pthread.h>
  3. #include <math.h>
  4.  
  5. int a, b, c;
  6. float delta, r1, r2;
  7.  
  8. void* solve_equation(void* args) {
  9.     delta = sqrt(b*b-4*a*c);
  10.     if(delta < 0)
  11.         printf("The equation has no roots.\n");
  12.     if(delta == 0) {
  13.         r1 = -b/(2*a);
  14.         printf("The equaion has one root: %0.2f\n", r1);
  15.     }
  16.     if(delta>0) {
  17.         r1 = (-b + sqrt(delta)) / (2*a);
  18.         r2 = (-b - sqrt(delta)) / (2*a);
  19.         printf("root 1=%.2f\nroot 2=%.2f", r1, r2);
  20.     }
  21.     pthread_exit(0);
  22. }
  23.  
  24. int main() {
  25.     pthread_t thrd;
  26.     a=1;
  27.     b=-5;
  28.     c=6;
  29.     pthread_create(&thrd, NULL, solve_equation, NULL);
  30.     pthread_join(thrd, NULL);
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement