The trouble is you think you have time. Your success depends on how you utilize your time.

C++ Program to Print that a number is composite number or a prime number and also print the factors of that number which is taken by input.

How to write a C++ program that prints the factors of the number and also prints that a number is a prime number or a composite number by taking the number from the user.

using namespace std;
#include<iostream>
int main()
{
cout<<"www.moznum.blogspot.com"<<endl<<endl;

int i,n,c=0;
cout<<"Enter the number: ";
cin>>n;
cout<<endl<<"The Factors are: "<<endl;
for(i=1;i<=n;++i)
 {
     if(n%i==0)
      {
 cout << i <<endl ;
        c++;
        
  }
 }
cout<<endl<<"And. . . "<<endl;  
  if(c==2)
  cout<<n<<" is a Prime Number";
  else
  cout<<n<<" is Composite Number. !!";
}









You can also search this topic by this:

2 comments:

  1. A prime number is a whole number greater than 1, which is only divisible by 1 and itself. First few prime numbers are : 2 3 5 7 11 13 17 19 23
    2 is the only even Prime number. Prime number program in C++. Every prime number can represented in form of 6n+1 or 6n-1, where n is natural number. 2, 3 are only two consecutive natural numbers which are prime too.

    ReplyDelete
  2. Sir, could you make a code for composite triangle. I hope you can help sor

    ReplyDelete