Friday, 11 December 2015

write a program that inputs a number and tells whether it is prime or composit number using loop in c++

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{ int c,num,p;
p=1;
cout<<"Enter an integer"<<endl;
cin>>num;
for(c=2;c<=num/2;c++)
if(num%c==0)
 {
 p=0;
 break;}
 if(p==1)
 cout<<num<<" is a prime number";
 else
 cout<<num<<" is a composite number";
 getch()
}

No comments:

Post a Comment