Sunday, July 12, 2009

How do programmers use math to create stuff. I know C++ and I am good at Math and I can't find ways to put

it all together. DO they programmers think first on paper with math. Please help me. Just show me how they can be combine. Thank u

How do programmers use math to create stuff. I know C++ and I am good at Math and I can't find ways to put
you need to use and exercise creative powers


and innovative thinking.
Reply:You must know the algorithm of a problem.
Reply:In order to put your math skills to work, you must first identify what you would like to accomplish. Remember, programming is done with a purpose, not simply because there is nothing else to do. For instance, you might want to create software to run simulations (e.g. DNA folding, like the folding@home project). You would then identify the process by which such folding takes place. Mathematically, you devise how to perform the necessary calculations. Then you translate those into programmatic functions in a way that is most efficient for a computer to use. So in the end, it depends on what you would like to accomplish--you simply can't apply skills without a goal.





If you're asking for something you can try doing realistically, an old problem that mathematically inclined programmers like to tackle is a prime number generator. This seems like an easy task at first, but making one that works very fast is a great challenge. Try it out. To get you started, here's a horribly inefficient prime number function I made in my first C++ class:





int primeNumberOutput(int params[])


{


int counter = 2,


counter2 = 1,


innerCounter,


primeNumbersCounter = 0,


primeNumbersSum = 0,


primeNumbersExpected = params[0],


factors,


columns = params[1],


columnsWidth = params[2];





do


{


factors = 0;


innerCounter = 1;





do


{


// determines how many factors counter has


if (counter % innerCounter == 0)


factors++;


innerCounter++;


}


while (innerCounter %26lt;= counter);





// following condition determines if a number is prime


if (factors %26lt;= 2)


{


primeNumbersCounter++;


primeNumbersSum += counter;





cout %26lt;%26lt; setw(columnsWidth) %26lt;%26lt; counter;





// next two conditions format the output


if (primeNumbersCounter %26lt; primeNumbersExpected)


cout %26lt;%26lt; ", ";





if (counter2 % columns == 0 %26amp;%26amp;


primeNumbersCounter %26lt; primeNumbersExpected)


cout %26lt;%26lt; endl;





counter2++;


}





counter++;


}


while (primeNumbersCounter %26lt; primeNumbersExpected);





return primeNumbersSum;


}





See if you can improve upon it's design to make it work more efficiently.
Reply:they have to think about the logic of the programs. Most logics involve maths. for examples you need maths to iterate through a list to get the data you might want. so most programmers work out the logic flow on paper first before they start the actually coding on the computer.
Reply:Logic is required for solving any problem.


In the process of deciding the flow of the program u decide the logic and then put that flow in your program.


It'll come by little practice. Make 10 programs by yourself and u'll find everything falling in place.
Reply:I read a book about famous hackers (good sense hackers) like Linus Torvalds and he said that he doesn't usually write out things on paper. But that's just him. Whatever works for you to organize your ideas. You need to develop your own style.


No comments:

Post a Comment