How to use array in a function? - arrays

can you fix me this code, which uses the Erastothenes sieve for a limit specified in n.
Thanks in advance.
P.S. This gave me 16 errors.
my code
And I think most of the code is done right

Related

How would you rewrite this pseudo code?

Hey guys just doing some code practice and I came across this question it reads, Rewrite the pseudo code so that a FOR loop is used instead. Just wondering how you would do it cause I'm very lost. thanks for the help
value = 0.0
While value <= 1.0
OUTPUT value
value = value + 0.1
ENDWHILE
"Pseudocode is subjective and nonstandard. There is no set syntax that you absolutely must use for pseudocode, but it is common professional courtesy to use standard pseudocode structures that other programmers can easily understand. If you are coding a project by yourself, then the most important thing is that the pseudocode helps you structure your thoughts and enact your plan. If you are working with others on a project—[...]—it is important to use at least some standard structures so that everyone else can easily understand your intent."link
It won't be of any help to you if someone else rewrites this code for you. You should first understand what are the benefits of using pseudo-code and what are the common structures and then try to answer your own question. If you cannot manage to get the right answer, come back and ask for help on the piece of code you wrote. Try reading the link I provided or any other pseudocode tutorial and then try solving the problem. It might be hard at first but will bring a lot more benefits in the end.
for value = 0.0 to 1.0 step 0.1 do
output value
step is meant to describe the changes to value after each iteration

cs50 pset1 greedy. I didn't have to use %?

Here is my code for the pset1 greedy. Now it all works from what I can tell and tested and used cs50 check aswell...
Problem is it was hinted in the walk through and me having to look up how to use round properly, that I maybe should of used modular somewhere? I get what it does. eg 10 % 3 = 1. Is it worth doing it again using modular %. Also any advice on my method? Thanks in advance.
To calculate how much coins are needed you can divide change_int by the current coin value. To calculate how much change is left you can the do the same calculation, but only with % instead of /.
This will speed up the programm for large change values because you don't have to use the while loop anymore.
Also as Weather Vane wrote in a comment you can put the four coin values in an array and do the calculation in a loop.

Finding Largest Values for (N) in Ackermann Function

In C, I have implemented the Ackermann function but am now attempting to find largest values for N. For example, if m = 1 find the largest value of n that computes correctly. So far I have been using "guess and check" but it seems there has to be a better, and more accurate, method. Could anyone offer some guidance? The Ackerman function has a lot to do with how many stacks can be processed so perhaps this question is purely arbitrary... Any help appreciated, thanks!

Prediction of the next number generated by C (glibc) rand()

Given a series of numbers generated by rand(), how can I predict the next value? Brute force is out of the question.
I'm aware that rand() is basically a linear congruential generator, but also makes bit shifting. What theory can I use to crack it? Any hints will be most welcome :)
#unwind: thanks for the advice! I was wrong in some places, and the documentation got me on the right track.
Actually, predicting is a piece of cake when you know a sequence of 30 (or so) numbers. The 'computed' answer will be right in 50% of cases. More details present in the link provided by unwind, or in a simplified code: http://www.mathstat.dal.ca/~selinger/random/

Matrix solving with C (within CUDA)

As part of a larger problem, I need to solve small linear systems (i.e NxN where N ~10) so using the relevant cuda libraries doesn't make any sense in terms of speed.
Unfortunately something that's also unclear is how to go about solving such systems without pulling in the big guns like GSL, EIGEN etc.
Can anyone point me in the direction of a dense matrix solver (Ax=B) in straight C?
For those interested, the basic structure of the generator for this section of code is:
ndarray=some.generator(N,N)
for v in range N:
B[v]=_F(v)*constant
for x in range N:
A[v,x]=-_F(v)*ndarray[x,v]
Unfortunately I have approximately zero knowledge of higher mathematics, so any advice would be appreciated.
UPDATE: I've been working away at this, and have a nearly-solution that runs but isn't working. Anyone lurking is welcome to check out what I've got so far on pastebin.
I'm using Crout Decomposition with Pivoting which seems to be the most general approach. The idea for this test is that every thread does the same work. Boring I know, but the plan is that the matrixcount variable is increased, actual data is put in, and each thread solves the small matrices individually.
Thanks for everyone who's been checking on this.
POST-ANSWER UPDATE: Finished the matrix solving code for CPU and GPU operation, check out my lazy-writeup here
CUDA won't help here, that's true. Matrices like that are just too small for it.
What you do to solve a system of linear equations is LU decomposition:
http://en.wikipedia.org/wiki/LU_decomposition
http://mathworld.wolfram.com/LUDecomposition.html
Or even better a QR decomposition with Householder reflections like in the Gram-Schmidt process.
http://en.wikipedia.org/wiki/QR_decomposition#Computing_the_QR_decomposition
Solving the linear equation becomes easy afterwards, but I'm afraid there always is some "higher mathematics" (linear algebra) involved. That, and there are many (many!) C libraries out there for solving linear equations. Doesn't seem like "big guns" to me.

Resources