Trouble understanding the logic of prime sieve using fork and pipe [closed] - c

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 10 hours ago.
Improve this question
So I'm trying to use fork and pipe in order to find the prime numbers from 1-35. I'm having trouble understanding how to store my prime numbers without overwriting them in future steps. For example, say I have the number 2, and I decide it is prime, how do I store that value as prime and store values like 3, 5, 7 as the same variable? I think I'm mostly having trouble understanding how to use pipe and fork recursively. Thanks.
I tried creating a parent process that writes in the numbers 1-35 and a child process that takes said number and compares it to the numbers that were previously decided as prime, and then printing the result. This did not work.

Related

How to dynamically change the writing file inside a for loop [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 months ago.
Improve this question
I am writing a Monte Carlo simulation in which I take "measurements" of the magnetization every 1 correlation time. I want to have 3 for loops. The first is to change the temperature and inside it (with constant temperature) 2 other for loops in which I run e.g 10 correlation times, so 10 measurements of M. My question is, how can I switch the txt file in which I write (with fprintf) M, for different temperatures? Shape of the 3 loops I want

Is this a good approach for finding number of prime numbers within a certain range? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
During my programming exam in college I was told to write a program that can find the prime numbers from 0 to n.
My approach was divide the numbers by 2,3,5 and 7, and the ones that doesn't returns a remainder of value 0 would be a prime number.
Is this a good approach for the solution?
Thanks!
121 = 11 * 11 would be the first non-prime listed as prime by your code.
So your code is only a solution up to n = 120.
I.e.: No.

Generating Random Numbers [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Given a set of consecutive numbers S1 i.e [1,2,3,4,5,6,7,8,...N1].Also a small set S2 of consecutive numbers i.e [1,2,3,4,5,6....N2]. N2<< N1
Now starting from first element i.e S2[i](i: 1 to N2) of set S2, you have to pick S2[i] consecutive RANDOM numbers from S1. Once you pick any number from S1,in any i(th) turn you can't pick it anymore in any other turn.
So my main goal is learn 'How To pick RANDOM numbers in such way'.This question is not part of any Coding Competition, or Homework. It is only for learning purpose.
If possible please use C language,as i am beginner in programming.
Use rand() function defined in C standard Library, and make an array of length in which you have to produce random number. Then on getting the particular number, simply put a value 1 in the particular array space. Again if you get same random number where the value is 1 in the array then start random function again so as to get a new random element.

Which datatype is used for 10^500 in c language [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Problem Statement
Addition is a very basic operation in mathematics. Jimmy was very weak in addition, so his father decided to teach him. Jimmy is given a number and has to perform addition on all the digits of that number till that the large number gets converted into a single digit. Your task is to prepare a program for him so that he can easily find out the final number.
Input Format
First line contains T (1<=T<=100) the number of test cases.
Each test case contains integer N (1<=N<=10^100).
Output Format
For each test case, output the one digit number by repeatedly adding the digits.
Constraints
1<=T<=100
1<=N<=10^500
I'd represent the very large input number as char, and the total of the digits (first pass) will easily fit in an int. You'll need a little more than simple arithmetic, but it shouldn't be difficult (case seems a likely way to manage the job).

I need a better explanation of the 100 doors program [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
How would I do this in 1 loop since I need to loop again and close every second door? Do they want me to loop through the program 100 times? Should I be using pointers ?
Yes, you should loop through the program 100 times if you want to simulate this behavior.
But if you want to know the final condition(Open/Close) then you can have better algorithm:
As every perfect square number only have odd number of factor, if number is perfect square then final condition of door is open otherwise door is close.
If you are interested see perfect square number and Why perfect squares only have odd numbers of factor .

Resources