Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Parallel Processing ProgramsRSS Feeds

PROGRAM THAT CHECK WHETHER THE GIVEN NUMBER IS PRIME IN PARALLEL

Posted By: Phoebe Brown     Category: C Programming     Views: 4186

PROGRAM THAT CHECK WHETHER THE GIVEN NUMBER IS PRIME IN PARALLEL.

Code for PROGRAM THAT CHECK WHETHER THE GIVEN NUMBER IS PRIME IN PARALLEL in C Programming

#include "forkjoin.h"
#include "shared.h"

main()
{
    int a[10],n;
    int *flag,fect=1,nproc;
    int i,pid,shmid;
    printf("Enter the value of the no. n : ");
    scanf("%d",&n);
    printf("Enter the no. of process  : ");
    scanf("%d",&nproc);
    flag=(int *) create_memory(sizeof(int)*nproc,&shmid);
    for(i=0;i<nproc;i++)
        flag[i]=0;
    pid=create_process(nproc);
    for(i=pid+2;i<n;i+=nproc)
    {
        if(n%i==0)
            flag[pid]=1;
    }
    join_process(nproc,pid);
    for(i=0;i<nproc;i++)
    {
        if(flag[i]==1)
        {
            printf("Given no. is not prime\n");
            exit(1);
        }
    }
    printf("Given no. is prime\n",fect);
    clear_memory(&shmid);
}
  
Share: 



Phoebe Brown
Phoebe Brown author of PROGRAM THAT CHECK WHETHER THE GIVEN NUMBER IS PRIME IN PARALLEL is from London, United Kingdom.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!