Is it prime number or not

Prompt user for an integer

Read the integer into **n**

IF **n** is less than 2

Set **prime** to 0 ( 0 means false, i.e. **n** is not prime )

ELSE

Set **prime** to 1 ( 1 means true, i.e. assume **n** is prime )

FOR values of **i** from 2 to **n** - 1 ( **i** represents all numbers smaller than n )

IF **n** divided by **i** gives no remainder

Set **prime** to 0 ( 0 means false, i.e. **n** is not prime )

BREAK ( jump out from the loop )

END IF

END FOR

END IF

IF **prime** = 1

Print message for prime number

ELSE

Print message for not prime number

END IF

I follow this algorithm but it's not working ...

Code:

`#include <stdio.h>`

int main ()

{

int n, i, prime;

printf("Enter a number : ");

scanf("%d", &n);

if (n<2)

{

prime = 0;

}

else

{

prime = 1;

for (i=2;i<n;n--)

{

if (n%i==0)

{

prime = 0;

break;

}

}

}

if (prime==1)

{

printf("Prime number\n", n);

}

else

{

printf("Not a prime number\n", n);

}

return 0;

}

Anyone help please?