Write a program that takes a 3 digit number n and finds out
whether
the number 2^n + 1 is prime, or if it is not prime find out its
factors.
Answer Posted / beena
#include <iostream>
using namespace std;
void prime_num(int);
int main()
{
cout << " Enter a number ";
int num = 0;
cin >> num;
if((num/100>0)&&(num/100<10))
printf("\nNumber is of 3 Digits");
else
printf("\nNot a 3 digit number");
bool flag = prime_num(num);
if(!flag)
{
printf("\nNumber %d is not a prime",n);
printf("\nIts factors are:\n\t");
x=2;
while(num!=1)
{
while(num%x==0)
{
num=num/x;
printf("%d ",x);
}
x++;
}
}
}
bool prime_num( int num)
{
bool isPrime=true;
int checkNum = 1;
for(int i = 1; i <=num; i++)
checkNum *= 2;
checkNum +=1;
for ( int i = 0; i <= checkNum; i++)
{
for ( int j = 2; j <= checkNum; j++)
{
if ( i!=j && i % j == 0 )
{
isPrime=false;
break;
}
}
if (isPrime)
{
cout <<"Prime:"<< i << endl;
}
isPrime=true;
}
return isPrime;
}
Is This Answer Correct ? | 5 Yes | 5 No |
Post New Answer View All Answers
Code for Two Classes for Doing Gzip in Memory?
i don't know about working of nested for loop can any one help me
Write a C/C++ program that connects to a MySQL server and displays the global TIMEZONE.
Performance Algorithm A performs 10n2 basic operations and algorithm B performs 300 lg n basic operations. For what value of n does algorithm B start to show its better performance?
What output does this program generate as shown? Why? class A { A() { cout << "A::A()" << endl; } ~A() { cout << "A::~A()" << endl; throw "A::exception"; } }; class B { B() { cout << "B::B()" << endl; throw "B::exception"; } ~B() { cout << "B::~B()"; } }; int main(int, char**) { try { cout << "Entering try...catch block" << endl; A objectA; B objectB; cout << "Exiting try...catch block" << endl; } catch (char* ex) { cout << ex << endl; } return 0; }
Code for Method of Handling Factorials of Any Size?
Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.
how to take time as input in the format (12:02:13) from user so that controls remains between these columns?
What output does the following code generate? Why? What output does it generate if you make A::Foo() a pure virtual function? class A { A() { this->Foo(); } virtual void Foo() { cout << "A::Foo()" << endl; } }; class B : public A { B() { this->Foo(); } virtual void Foo() { cout << "A::Foo()" << endl; } }; int main(int, char**) { A objectA; B objectB; return 0; }
Implement a command console for changing settings on a particular object. The command console should allow you to enter a string and will return the response (very similar to a terminal session). The commands are as follows: SET propertyname=newvalue will change the target object’s member named “propertyname” to have a value equal to “newvalue”. If the input value is incompatible (i.e. an int being set to a string), print out an appropriate error message. GET propertyname will print out the current value of the target object’s member named “propertyname”. GET * will print out a list of all target object members and their current values. The system should be extensible for future commands and should accept an arbitrary object, such that another developer could insert another object into the system and rely on the command console to get and set the properties correctly.
How can I Draw an ellipse in 3d space and color it by using graph3d?
write a program that prompt the user to enter his height and weight,then calculate the body mass index and show the algorithm used
how to write a program that opens a file and display in reverse order?
Ask the user to input three positive integers M, N and q. Make the 2 dimensional array of integers with size MxN, where all the elements of I (I = 1,…,M) line will be members of geometrical progression with first element equal to the number of line (I) and denominator q.
can you please write a program for deadlock that can detect deadlock and to prevent deadlock.