An algorithm to detect given number is Prime or Not Prime.

1. START
2. Initialize i=2 and p=2.
3. Enter any number to detect prime or Not as gno
4. Check is (gno% i==0) if TURE then continue else GOTO step 6
5. p=1.
6. Increment value of i. i.e i++.
7. Check is (i<gno) if TRUE then GOTO step 4.
8. Check is(p==0 or gno=2) then continue else GOTO step 11.
9. The Given number is prime.
10. GOTO step 12.
11. The number is NOT prime.
12. END

Flowchart  to detect given number is Prime or Not Prime.

C-Code to detect given number is Prime or Not Prime. using do….while loop

```#include<stdio.h>
void main()
{
int gno, i=2,p=0;
printf("Enter any no to detect prime or Not:");
scanf("%d",&gno);
do
{
if(gno% i==0)
p=1;
i++;
}while(i<gno);
if(p==0 || gno==2)
printf("\nThe Given number is prime :%d",gno);
else
printf("\nThe number is NOT prime :%d",gno);
}

```

Write a C Program to find a given number is prime or not using for loop.

```#include<stdio.h>
void main()
{
int gno,i,p=0;
printf("Enter any no to detect prime or Not:");
scanf("%d",&gno);
for(i=2;i<gno;i++)
{
if(gno% i==0)
p=1;
}
if(p==0 || gno==2)
printf("\nThe Given number is prime :%d",gno);
else
printf("\nThe number is NOT prime :%d",gno);
}```