techie summer
the summer season has started, and what a great way to enjoy it than to start hacking (or coding, for the misinformed) on old projects, and new ones as well...
however, to the un-tech savvy people reading this blog, i'm sorry but i would have to get a little technical. first of, i'd like to start with a snippet of code, which i hope would be helpful to you and your endeavors.
this (as you might notice in the near future) will check whether a number is prime. in my estimation, the running time of this algorithm is O(n^1/2) or [oh of square root of n] where n is the number to be checked for primality.
i came up with this and a few more useful code snippets while i was thinking about and checking on my coding abilities the past few days.
now, i will need to brush up on my programming skills because i think i'm way behind of the pack, and knowing how to code is something, and writing code that actually works is another. i have to got both, but still more work is required. anyway, i hope i have time to do what i love most to do, which is think.
chill! =)
the summer season has started, and what a great way to enjoy it than to start hacking (or coding, for the misinformed) on old projects, and new ones as well...
however, to the un-tech savvy people reading this blog, i'm sorry but i would have to get a little technical. first of, i'd like to start with a snippet of code, which i hope would be helpful to you and your endeavors.
#include <math.h>
int isprime(int n) {
int prime=1; /* assume that the number is prime */
int dlimit, dit;
if (n <= 3) /* the first 3 primes */
return prime;
if (!(n % 2)) /* if divisible by 2 (or even) */
prime = 0; /* it's not prime */
dlimit = (int) sqrt ( (double) n); /* result of sqrt is a double */
for (dit = 5; (dit <= dlimit) && (prime); dit+=2)
if (!(n % dit)) /* if divisible by odd numbers */
prime = 0; /* then it's not prime */
return prime;
}
this (as you might notice in the near future) will check whether a number is prime. in my estimation, the running time of this algorithm is O(n^1/2) or [oh of square root of n] where n is the number to be checked for primality.
i came up with this and a few more useful code snippets while i was thinking about and checking on my coding abilities the past few days.
now, i will need to brush up on my programming skills because i think i'm way behind of the pack, and knowing how to code is something, and writing code that actually works is another. i have to got both, but still more work is required. anyway, i hope i have time to do what i love most to do, which is think.
chill! =)
Comments
Post a Comment