//for statement
#include<stdio.h>
#include<conio.h>
int main()
{
int n,i,flag=0;
printf("ENter a positive integer:");
scanf("%d",&n);
for(i=2;i<n/2;i++)
{
if(n%i==0)
{
flag=1;
break;
}
}
if(flag==0)
printf("%d is a prime number",n);
else
printf("%d is not prime number",n);
return 0;
}
PRIME OR NOT USING RECURSION
//prime or not using recursion
#include <stdio.h>
int primeno(int, int);
int main()
{
int num, check;
printf("Enter a number: ");
scanf("%d", &num);
check = primeno(num, num / 2);
if (check == 1)
{
printf("%d is a prime number\n", num);
}
else
{
printf("%d is not a prime number\n", num);
}
return 0;
}
int primeno(int num, int i)
{
if (i == 1)
{
return 1;
}
else
{
if (num % i == 0)
{
return 0;
}
else
{
return primeno(num, i – 1);
}
}
}
PRIME OR COMPOSITE
/*PRIME OR COMPOSITE*/
#include<stdio.h>
int main()
{
int i,n,c=0;
printf ("Enter a number n");
scanf ("%d",&n);
for (i=1;i<=n;i++)
{
if(n%i==0)
c=c+1;
}
if (c==2)
printf ("The number is PRIME");
else
printf ("The number is COMPOSITE");
return 0;
}
/*1-100 Prime*/
#include<stdio.h>
int main()
{
int i,n,c=0;
for(n=1;n<=100;n++)
{
c=0;
for (i=1;i<=n;i++)
{
if(n%i==0)
c=c+1;
}
if (c==2)
printf ("%d\t",n);
}
}