- #1
smart_worker
- 131
- 1
this is the program which i wrote:
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void prime(int p)
{
if(p==0||p==1)
{
cout<<"neither prime nor composite"<<endl;
getch();
exit(1);
}
for(int i=2;i<p/2;i++)
{
if(p%i==0)
{
cout<<"composite"<<endl;
break;
}
else
cout<<"prime"<<endl;
}
}
void main()
{
int n;
clrscr();
cout<<"enter a number:"<<endl;
cin>>n;
prime(n);
getch();
}
it is not working for some numbers like 9,5,2,etc..
if i input 9
output is :
composite
prime
if i input 5
nothing is displayed
i debugged and no errors came
what exactly is wrong with this code?
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void prime(int p)
{
if(p==0||p==1)
{
cout<<"neither prime nor composite"<<endl;
getch();
exit(1);
}
for(int i=2;i<p/2;i++)
{
if(p%i==0)
{
cout<<"composite"<<endl;
break;
}
else
cout<<"prime"<<endl;
}
}
void main()
{
int n;
clrscr();
cout<<"enter a number:"<<endl;
cin>>n;
prime(n);
getch();
}
it is not working for some numbers like 9,5,2,etc..
if i input 9
output is :
composite
prime
if i input 5
nothing is displayed
i debugged and no errors came
what exactly is wrong with this code?