Scenario
You're working on a project that calculates different mathematical formulae. You start with a basic one that prints prime numbers.
Aim
Write a view that prints the prime numbers from 1 to 100 to the browser.
Steps for completion
Use a function called IsPrime along with the @function declaration, as follows:
Go to https://goo.gl/pCLuFD to access the code.
@functions
{
public bool IsPrime(int n)
{
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (var i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
}
<ul>
…
…
</ul>