Created
July 30, 2013 18:54
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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