W.A.P. C++

WAP | CPP | Programs in C++ | C++ Solutions

Snehil Khanor's Binary Log

write a program to check whether entered number is prime or not


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 :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int n,m;
  7. cout<<"Please enter a number: ";
  8. cin>>n;
  9. for (int i=2;i<=(n-1);i++)
  10. {
  11. if(n%i==0)
  12. //Coding by: Snehil Khanor
  13. //http://WapCPP.blogspot.com
  14. {
  15. cout<<"Not a prime";
  16. break;
  17. }
  18. else
  19. {
  20. cout<<"Prime";
  21. break;
  22. }
  23. }
  24. getch();
  25. }

14 comments:

Anonymous July 5, 2011 at 8:56 PM  

when entering 1,2,3 etc no result..........

alok July 30, 2011 at 2:54 PM  

#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();}

}

alok tiwari July 30, 2011 at 2:54 PM  

this would b ryt answer!!

freak July 30, 2011 at 2:55 PM  

#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();}

}

alok July 30, 2011 at 2:57 PM  

half da statement after pasting is missing ..due to this html stuff..ol da things inside angle brackets r gone :O..sad

prashant makur December 24, 2011 at 11:48 AM  

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();
}

Anonymous January 24, 2012 at 2:05 PM  

chutiye

somu March 2, 2012 at 6:46 AM  

it show error of misplaced error. why does it so

Anonymous April 23, 2012 at 8:04 PM  

the above code is not right, go get right code goto
http://www.bitavoncpp.com/example.html

Anonymous August 8, 2012 at 10:24 AM  

u know u all r ass hole...
mother fucker

Anonymous September 5, 2012 at 11:36 AM  

Shows not prime only when not divisible by 2.
9 ,25 such numbers are displayed as prime

Anonymous September 12, 2012 at 5:08 PM  

#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();
}

Poras21 June 2, 2013 at 3:31 PM  
This comment has been removed by the author.
Poras21 June 2, 2013 at 3:34 PM  

#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();
}

Search

About WAP C++

Here you'll find a wide range of programs' solution ranging from beginer level to advanced level.
All programs here are made, compiled and tested by me..and are running absolutely fine.. still if you find any bug in any program do let me know :)

Followers

Subscribe via email

Enter your email address:

Delivered by FeedBurner

my Binary Log

Blog Archive



eXTReMe Tracker