Answer to Question #154491 in C for s_395

Question #154491

Write a C system program that creates a process chain of 32 processes having the following characteristics. 1. Each process prints two prime numbers that are generated randomly in the range of 1-1000. 2. Each parent must wait for its child process to terminate.

Your answer


1
Expert's answer
2021-01-08T13:18:56-0500
#include <stdio.h>
#include <stdlib.h>
int checkPrimeNumber(int n);
int main() {
  int c, n;
  printf("two prime numbers that are generated randomly in the range of 1-1000");



  for (int i = 1; i <= 32; i++) {
      int temp = 0;
      while (temp != 2) {
          int number = 1 + rand() % 1000;
          if (checkPrimeNumber(number) == 1) {
              temp++;
              printf("%d ", number);
          }
      }
      printf("\n");
  }



  return 0;
}
int checkPrimeNumber(int n) {
    int j, flag = 1;
    for (j = 2; j <= n / 2; ++j) {
        if (n % j == 0) {
            flag = 0;
            break;
        }
    }
    return flag;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS