Skip to content

Commit 0880315

Browse files
Merge pull request #61 from Pulkit555/PrimalityTest
Added a C program to check primality
2 parents 1de234e + b085185 commit 0880315

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

PrimalityTest.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <stdio.h>
2+
#include <math.h>
3+
int main()
4+
{
5+
int T,N,a;
6+
printf("Enter the no. of test cases\n");
7+
scanf("%d",&T);//input the no. of test cases
8+
for(int i=0;i<T;i++)
9+
{
10+
int k=0;
11+
printf("Enter the no. you want to check whether it is prime or not\n");
12+
scanf("%d",&N);//input the no. you want to check
13+
if(N==1)
14+
printf("no\n");
15+
else
16+
{
17+
for(int j=2;j<=sqrt(N);j++)
18+
{
19+
a=N%j;
20+
if(a==0)
21+
{
22+
k++;
23+
break;//break is used to reduce time complexity
24+
}
25+
}
26+
if(k>0)
27+
printf("no\n");//it is not a prime no.
28+
else
29+
printf("yes\n");//it is a prime no.
30+
}
31+
}
32+
return 0;
33+
}

Screenshot.PNG

-204 KB
Binary file not shown.

a

8.26 KB
Binary file not shown.

0 commit comments

Comments
 (0)