fork download
  1. #include <iostream>
  2. #include <omp.h>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. printf("Fibonacci Series\n\n");
  8. int n = 10;
  9. int fib[n];
  10. fib[0] = fib[1] = 1;
  11.  
  12. #pragma omp parallel
  13. {
  14. #pragma omp for ordered
  15. for (int i = 2; i < n; i++)
  16. {
  17. #pragma omp ordered
  18. {
  19. fib[i] = fib[i-1] + fib[i-2];
  20. printf("Fib[%d] = %d\n", i, fib[i]);
  21. }
  22. }
  23.    }
  24. return 0;
  25. }
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
Fibonacci Series

Fib[2] = 2
Fib[3] = 3
Fib[4] = 5
Fib[5] = 8
Fib[6] = 13
Fib[7] = 21
Fib[8] = 34
Fib[9] = 55