How to write a C Program Fibonacci Multi Threaded and print the elements of Fibonacci Series in C Programming Language ?
Solution:
- #include <stdio.h>
- #include <omp.h>
- int main()
- {
- int n, a[100], i;
- // Setting number of threads to 2
- omp_set_num_threads(2);
- printf("Enter the number of Fibonacci numbers to be generated : \n > ");
- scanf("%d", &n);
- a[0] = 0; a[1] = 1;
- #pragma omp parallel
- {
- #pragma omp single
- for (i = 2; i < n; i++) {
- a[i] = a[i-1] + a[i-2];
- printf("Computation of Fibonacci number %d, thread_id is %d\n", i, omp_get_thread_num());
- }
- #pragma omp barrier
- #pragma omp single
- {
- printf("The elements of the fibonacci series are : \n");
- for (i = 0; i < n; i++) {
- printf("%d, thread_id is %d\n", a[i], omp_get_thread_num());
- }
- }
- }
- return 0;
- }
Learn More :
Element
- Given a numerical value, check if at least one of the elements of the vector is equal to the numerical value if so, say where in the negative case, say that there is no.
- C program to Given a vector (integer or real), determine what is the maximum value of element what is the position in which this element is located
- Write the procedure , which is one of a sum , a product and a geometric average in the panel for the NxM elements are located on opposite diagonal and main diagonal . Remind ! Counting only odd elements !
- Napisać funkcję obliczającą funkcję geometryczną w tablicy NxM elementowej z elementów o wartościach parzystych znajdujących się pod główną i ponad przeciwną przekątną.
- C Program Array NxM Elements Geometric/Arithmetic
- C Program To Returns the nth element of the Fibonacci sequence.
- C Program to search an element using linear search or binary search (menu driven program)
- C Program to accept n numbers from user & find out the maximum element out of them by using dynamic memory allocation
- C Program to accept m*n matrix from user and display the elements of given matrix using function
- C program to reverse an array elements using Dynamic Memory Allocation
- C Program to calculate the sum of elements of upper triangle of a n*n matrix using DMA
- C Program to accept n numbers from user store these numbers into an array & reverse an array elements using function
- C Program to accept 5 names from user & store these names into an array. Sort these array elements in alphabetical order
- Calculate sum of element of upper triangle of m*n matrix by using dynamic memory allocation
- Calculate sum of non-diagonal element in m*n matrix C Program
- Calculate sum of element of lower triangle of m*n matrix by using dynamic memory allocation
- C Program to Implemention Bubble Sort using array
- C Program to Create, Display, Insert and Deletion of Queue Elements
- Creation and Display of Elements in Both Forward and Reverse Direction in a Doubly Linked List
Fibonacci
Multi Threaded