PRIME NUMBERS BETWEEN TWO INTEGERS
Problem Description
Program to Display Prime Numbers Between Intervals Using Function
Note:
Include upper and lower limits in the output.
CODING ARENA
#include <stdio.h>
int check_prime(int num);
int main()
{
int n1,n2,i,flag;
scanf("%d%d",&n1,&n2);
for(i=n1;i<=n2;i++)
{
flag=check_prime(i);
if(flag==0)
printf("%d\n",i);
}
return 0;
}
int check_prime(int num)
{
int j,flag=0;
for(j=2;j<=num/2;j++)
{
if(num%j==0)
{
flag=1;
break;
}
}
return flag;
}
Test Case 1
Input (stdin)13
29
Expected Output
13
17
19
23
29
Test Case 2
Input (stdin)3
14
Expected Output
3
5
7
11
13
No comments:
Post a Comment