Skip to content

Instantly share code, notes, and snippets.

@krman009
Created July 30, 2013 18:54
Show Gist options
  • Save krman009/6115720 to your computer and use it in GitHub Desktop.
Save krman009/6115720 to your computer and use it in GitHub Desktop.
Prime number without the modulo operator and used another logic to define it. Like division without '/' operator.
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i,temp=0,temp2,a,b;
clrscr();
printf("Enter number to check whether prime or not:");
scanf("%d",&num);
for(i=2;i<num;i++)
{
a=num;
b=i;
while(a>=b)
{
a=a-b;
temp2=a;
}
if(temp2==0)
{
temp++;
break;
}
}
if(temp!=1)
{
printf("%d is prime.",num);
}
else
{
printf("%d isn't prime.",num);
}
getch();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment