fork download
//Assignment-1 Problem-1
#include <omp.h>
#include <stdio.h>
int main()
{
    int len;
    printf("Enter the length of the array: ");
    scanf("%d", &len);
    int Test_arr[len];
    printf("Enter %d elements of the array:\n", len);
    for (int i = 0; i < len; i++)
    {
        scanf("%d", &Test_arr[i]);
    }
    int sum = 0;
    #pragma omp parallel for reduction(+:sum)
    for (int i = 0; i < len; i++)
    {
        sum += Test_arr[i];
    }
    printf("Sum of array elements: %d\n", sum);
    return 0;
}
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