Prime number: A natural number which has exactly two distinct natural number divisors: 1 and itself.
A number is taken from user and is checked whether prime number or not.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
- #include<iostream.h>
- #include<conio.h>
- void main()
- {
- clrscr();
- int n,m;
- cout<<"Please enter a number: ";
- cin>>n;
- for (int i=2;i<=(n-1);i++)
- {
- if(n%i==0)
- //Coding by: Snehil Khanor
- //http://WapCPP.blogspot.com
- {
- cout<<"Not a prime";
- break;
- }
- else
- {
- cout<<"Prime";
- break;
- }
- }
- getch();
- }
14 comments:
when entering 1,2,3 etc no result..........
#include
#include
void prime();
void main()
{
prime();
}
void prime()
{
int n,m;
char z;
cout<<"enter the number you want to check whether its prime or not :"<>n;
m=n-1;
if(n==1 || n==2 || n==3)
{cout<>z;
if (z=='y')
{ prime();}
}
this would b ryt answer!!
#include
#include
void prime();
void main()
{
prime();
}
void prime()
{
int n,m;
char z;
cout<<"enter the number you want to check whether its prime or not :"<>n;
m=n-1;
if(n==1 || n==2 || n==3)
{cout<>z;
if (z=='y')
{ prime();}
}
half da statement after pasting is missing ..due to this html stuff..ol da things inside angle brackets r gone :O..sad
enter the no and check prime or not?
#include
main()
{
int n,i,c=0;
printf(" enter any no..");
scanf("%d"&n);
for(i=2;i0)
printf("not prime");
getch();
}
chutiye
it show error of misplaced error. why does it so
the above code is not right, go get right code goto
http://www.bitavoncpp.com/example.html
u know u all r ass hole...
mother fucker
Shows not prime only when not divisible by 2.
9 ,25 such numbers are displayed as prime
#include
#include
void main ()
{ int n,flg;
cout<<'enter no : ';
cin>>n;
flg=0;
for(i=2;i<n/2;i++)
{
if(n%i==0)
flg=1;
}
if(flg=0)
cout<<i;
getch();
}
#include
#include
void main()
{
int a,r,i;
int factor=0;
cout<<"Enter a no. \n";
cin>>a;
for(i=1;i<=a;i++)
{
r=a%i;
if(r==0)
{
factor=factor+1;
}
}
if(factor==2)
cout<<a<<" is prime \n";
else
cout<<a<<" is not prime \n";
getch();
}
Post a Comment