#include<stdio.h>
#include<conio.h> //header file declaring
void main()
{
int a,i;
clrscr();
printf("\n Enter the Number:"); //get value
scanf("%d",&a);
if(a%2==0) {
printf("\n Not prime number");
} else {
for(i=3; i<a; i=i+2) {
if(a%i==0) {
printf("\n Not a prime");
break;
}
}
printf("\n Prime number");
}
getch();
}
vinodhsml
0
Newbie Poster
Recommended Answers
Jump to Post
void main()
Whatever happened to "int main()" in the 80s anyway?
Jump to PostFor finding larger primes, quicker:
1) #include <math.h>
2) in the outer loop, save the sqrt() of the number being checked, add one to it
3) in the inner for loop, stop at < that number you just saved. You never need
to go any higher.4) if …
Jump to Post@ashok1514: look what a disaster you did! Now the op (vinodhsml) will simply copy the code without trying out Adak's advise.
And oh, guess what, if the op blindly copies it, he'll run into problems as your snippet contains repeated code(!!!).
And also, the code you gave him …
All 9 Replies
D33wakar
36
Posting Whiz in Training
pseudorandom21
166
Practically a Posting Shark
cse.avinash
-1
Junior Poster
Adak
419
Nearly a Posting Virtuoso
ashok1514
-4
Newbie Poster
vinodhsml
0
Newbie Poster
NP-complete
42
Junior Poster
Prateek nandan
-4
Newbie Poster
reojavier
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.