A function that brings back the prime number just before it? Is there a function that brings the prime number just before it?
I.e P(18)=17 P(6)=5 P(28)=23;
I know how weird that sounds.
 A: Standard notations are $p_n$ for the $n^{th}$ prime and $\pi(n)$ for the number of primes less than or equal to $n$.  Combining these we have $p_{\pi(n-1)}$ as an expression for the largest prime less than $n$.
A: (I am assuming this is not a notational question)
If you want an algorithm to find the largest prime less than n, then it is simple. Consider n-1. Check to see if it has any divisors other than 1 and itself. If it doesn't, this is the largest prime. If it does have divisors other than 1 and itself, consider n-2 in the same manner, then n-3. Continue until you reach a prime.
If you want an efficient algorithm, that rather depends on what you care about. As I said in the comments, if you want to do this many times but your numbers are less than (say) 100 million, then you should build a sieve of Eratosthenes http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes to precalculate which are prime. Then you just step down until you reach a prime.
If this is a one-off calculation then calculating every prime in advance is inefficient and if the numbers are large will consume a lot of memory. So you need to have some method eg isPrime(n) which returns true if the number is prime. Then you just call this for n-1, n-2, etc until you get a prime. https://stackoverflow.com/questions/1538644/c-determine-if-a-number-is-prime explores this in some detail.
