Barrier synchronization in OpenMP (OMP BARRIER)

This exercise presents a simple program to demonstrate the use of OMP BARRIER. Compile and run the code provided below. Is the output correct? How can you use OMP BARRIER to ensure correct output?

 

#include 
#include 

int main(){
      int a[21],b[21],c[21],i,j;
      int d[21], e[21];

      for(i=1;i<=20;i++){
         a[i] = 0;
         b[i] = i;
         c[i] = 2*i;
         d[i] = 21-i;
      }

#pragma omp parallel private(i,j)
{
      j = omp_get_thread_num();

#pragma omp for nowait
      for(i=1;i<=20;i++){
         a[i] = b[i]+c[i]+100*j;
      }

#pragma omp for
      for(i=1;i<=20;i++){
         e[i] = a[d[i]];
      }

#pragma omp master
 {
      for(i=1;i<=20;i++){
        printf("%d %d %d
",i, e[i], a[d[i]]);
      }
 }
}
      return (0);
}