Check a number is prime or not


//WAP to check a number is prime or not
#include<stdio.h>
void main()
{
int n,i;
printf("Enter a number");
scanf("%d",&n);
for(i=2;i<n;i++)
{
if(n%i==0)
{
printf("%d is not a prime number",n);
break;
}
}
if(i==n)
{
printf("%d is a prime number",n);
}

}

Display prime numbers between two numbers


//WAP to display prime numbers between two numbers.
#include<stdio.h>
void main()
{
int n1,n2,i,c=0;
printf("Enter the range ");
scanf("%d%d",&n1,&n2);
while(n1<n2)
{ c=0;
for(i=2;i<=n1/2;i++)
{
if(n1%i==0)
{
c=1;
break;
}
}
if(c==0)
{
printf("\n%d",n1);
}
++n1;
}

}
 


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.