C++/C++

Advertisement


Question
This is a C++ question
Question:A number can be shown to be a prime number if it is excatly divisible only by itself and by 1. Write a function that takes an integer parameter and return true of false depend whether or not the integer is a prime number. Please give me the full code.

Answer
int inum;
 cout<<"enter the number";
 cin>>inum;
 bool primeornot;
 for( int i =2;i<=9;i++)
 {
      if((inum % i) == 0)
       primeornot = false;
 }  
 if(primeornot)
   cout<<"num is a prime number";
 else
   cout<<"num is not prime;

I have provided the logic to check whether the number is prime. You can use it in any function

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


rakshitha

Expertise

Difficult questions related to C .

Experience

C ,vc ,opc ,windows CE, ActiveX

Education/Credentials
Masters in electrical engineering

©2016 About.com. All rights reserved.