0% found this document useful (0 votes)
9 views3 pages

Ass3 Edited

Kie. Iwie is ss us shebsus e. S s s e s. Sssss

Uploaded by

Rooman M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Ass3 Edited

Kie. Iwie is ss us shebsus e. S s s e s. Sssss

Uploaded by

Rooman M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <stdio.

h>

#include <omp.h>

// Function to calculate factorial

int factorial(int n) {

int result = 1;

for (int i = 1; i <= n; i++) {

result *= i;

return result;

// Function to sum the first 10 elements

int sum_of_first_10() {

int sum = 0;

for (int i = 1; i <= 10; i++) {

sum += i;

return sum;

// Function to check if a number is even or odd

const char* even_or_odd(int n) {

return (n % 2 == 0) ? "Even" : "Odd";

}
// Function to check if a number is prime

int is_prime(int n) {

if (n <= 1) return 0;

for (int i = 2; i <= n / 2; i++) {

if (n % i == 0) return 0;

return 1;

int main() {

int number = 5; // Change this number as needed

int factorial_result, sum_result, prime_result;

const char* even_odd_result;

#pragma omp parallel num_threads(4)

int thread_id = omp_get_thread_num();

if (thread_id == 0) {

factorial_result = factorial(number);

printf("Thread 1: Factorial of %d is %d\n", number, factorial_result);

} else if (thread_id == 1) {

sum_result = sum_of_first_10();

printf("Thread 2: Sum of first 10 elements is %d\n", sum_result);

} else if (thread_id == 2) {
even_odd_result = even_or_odd(number);

printf("Thread 3: %d is %s\n", number, even_odd_result);

} else if (thread_id == 3) {

prime_result = is_prime(number);

printf("Thread 4: %d is %s\n", number, prime_result ? "a prime number" : "not a prime


number");

return 0;

You might also like