Find Prime Numbers

Learn and Trouble Shoot Problems Related to C-Language here.

Find Prime Numbers

Unread postby rajeevmahura » Thu May 22, 2008 6:35 pm

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b=2,c;
clrscr();
printf("Enter the value of which u want to cheak");
scanf("%d",&a);
if(a%2!=0)
{
for(b=2;b<=a-1;b++)
{
a=a/b;
}
printf("the nos u have input is prime no");
}
else
{
printf("The no u have enter is not a prime no");
}
getch();
}
--Regards--
Rajeev Mahura
Servers & Storage Professional
http://about.me/rajeevmahura
User avatar
rajeevmahura
 
Posts: 144
Joined: Tue May 20, 2008 5:22 pm
Location: Bangalore | New Delhi
Full Name: Rajeev Mahura
Date Of Birth: 15 Jan 1984
Address: New Delhi
Profession: DOEACC Trainer
DOEACC Center: DOEACC DELHI
Mobile No: 0

Re: Find Prime Numbers

Unread postby manojthesingham » Tue Sep 01, 2009 6:42 am

#include<stdio.h>
#include<conio.h>
typedef enum{false=0,true=1}boolean;
boolean prime_number(int x)
{
int i;
/*
5 7 11 13 ..... 37 ... 101
6-1 6+1 12-1 12+1 36+1 102-1
*/
if((x==2)||(x==3))
return true;
if(((x+1) % 6 == 0)||((x-1) % 6 == 0))
{
for(i=3;i<(x/2);i+=2)
if((x%i)==0)
return false;
return true;
}
return false;
}
int main(int argc,char **argv)
{
int x;
printf("Enter the number to check whther it is prime or not : ");
scanf("%d",&x);
printf("%s",prime_number(x)?"PRIME Number":"Not A PRIME Number");
getch();
return 0;
}
If world is running, then I am idle..
If I am idle, then the world is running
User avatar
manojthesingham
 
Posts: 15
Joined: Tue Sep 01, 2009 5:39 am
Location: Coimbatore,Tamilnadu
Full Name: manoj
Date Of Birth: 31 Jul 1989
Address: Coimbatore18Tamilnadu
Mobile No: 0


Return to C-Language

Who is online

Users browsing this forum: No registered users and 2 guests

cron