fork download
  1. //Assignment-1 Problem-1
  2. #include <omp.h>
  3. #include <stdio.h>
  4. int main()
  5. {
  6. int len;
  7. printf("Enter the length of the array: ");
  8. scanf("%d", &len);
  9. int Test_arr[len];
  10. printf("Enter %d elements of the array:\n", len);
  11. for (int i = 0; i < len; i++)
  12. {
  13. scanf("%d", &Test_arr[i]);
  14. }
  15. int sum = 0;
  16. #pragma omp parallel for reduction(+:sum)
  17. for (int i = 0; i < len; i++)
  18. {
  19. sum += Test_arr[i];
  20. }
  21. printf("Sum of array elements: %d\n", sum);
  22. return 0;
  23. }
Success #stdin #stdout 0s 5304KB
stdin
8
3 5 4 2 1 2 3 9
stdout
Enter the length of the array: Enter 8 elements of the array:
Sum of array elements: 29