Display The Pairs Of Prime Number That Differ By 2 Of The Given Range
Source code :-
#include<stdio.h>
int check_prime(int n)
{
int i;
if(n<2)
return 0;
for(i=2;i<=n/2;i++)
{
if(n%i==0)
return 0;
}
return 1;
}
int main()
{
int i,a,b;
printf("Enter the lower bound: ");
scanf("%d",&a);
printf("\nEnter the upper bound: ");
scanf("%d",&b);
printf("\nTwin prime numbers are:\n\n");
for(i=a;i<=b;i++)
{
if(check_prime(i)&&check_prime(i+2))
printf("(%d,%d) ",i,i+2);
}
return 1;
}
Input-Output :-
abhi@hp-15q-laptop:~$ gcc pfactor.c
abhi@hp-15q-laptop:~$ ./a.out
Enter the lower bound: 10
Enter the upper bound: 100
Twin prime numbers are:
(11,13) (17,19) (29,31) (41,43) (59,61) (71,73)
إرسال تعليق