Consider the Factoral function it can be writtin in the following ways
Iterative
long int factorial(long int x)
{
long int h=1
for (;x>0;x--)
h*=x;
return h;
}
Recursive
long int factorial (unsigned long int x)
{
if (!x) return 1;
return x*factorial( x-1);
}
The First on is longer but I'm told more efficient after the program compiles. The second one is prettier but waistes memory (granted probally not a lot). I usually will sacrifice code prettyness over run time efficiency. The point though is that is my philosophy. On a major project it might not be praticle to do that. Both codes express a deep philosophy of not only programming but logic. Also look at the error checking. (Not anything serios just so I don't inifite loop) The first on does it in the for loop while the second one does it by Saying that everything is positive. The second one looks prettier but since negative numbers are expressed in ones complement they are actually very big and that loop might cause an error run time. But it is still way cooler looking to write. This is just on example of one function of how code can be art
Consider the Factoral function it can be writtin in the following ways Iterative long int factorial(long int x) { long int h=1 for (;x>0;x--) h*=x; return h; } Recursive long int factorial (unsigned long int x) { if (!x) return 1; return x*factorial( x-1); } The First on is longer but I'm told more efficient after the program compiles. The second one is prettier but waistes memory (granted probally not a lot). I usually will sacrifice code prettyness over run time efficiency. The point though is that is my philosophy. On a major project it might not be praticle to do that. Both codes express a deep philosophy of not only programming but logic. Also look at the error checking. (Not anything serios just so I don't inifite loop) The first on does it in the for loop while the second one does it by Saying that everything is positive. The second one looks prettier but since negative numbers are expressed in ones complement they are actually very big and that loop might cause an error run time. But it is still way cooler looking to write. This is just on example of one function of how code can be art