Untitled

 avatar
unknown
plain_text
2 years ago
505 B
4
Indexable
D) #include <stdio.h>
#include <pthread.h>

#define ARRAY_SIZE 5

int array[ARRAY_SIZE] = {1, 2, 3, 4, 5};
int sum = 0;

void *calculateSum(void *args) {
    for (int i = 0; i < ARRAY_SIZE; i++) {
        sum += array[i];
    }

    pthread_exit(NULL);
}

int main() {
    pthread_t thread;

    // Create a thread
    pthread_create(&thread, NULL, calculateSum, NULL);

    // Wait for the thread to finish
    pthread_join(thread, NULL);

    printf("Sum of array elements: %d\n", sum);

    return 0;
}
Editor is loading...