A number is taken from user and is checked whether prime number or not.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n,m;
printf("Please enter a number: ");
scanf("%d",&n)
for (int i=2;i<=(n-1);i++)
{
if(n%i==0)
{
printf("Not a prime");
break;
}
else
{
printf("Prime");
break;
}
}
getch();
}
===========================================
prime number between 1 to 100.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n=0;
for(i=2;i<=100;i++)
{
for(j=1;j<=i;j++)
{
if(i%j==0)
{
n++;
}
}
if(n==2)
printf("%d\n",i);
n=0;
}
getch();
}
No comments:
Post a Comment