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 / sumitgaur2010

#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
int main()
{
int i,n,num,p=1;
cout<<"enter the number";
cin>>n;
num=pow(2,n)+1;
for(i=2;i<num/2;i++)
{
if(num%i==0)
{
p=0;
break;
}
}
if(p==1)
cout<<"prime";
else if(p==0)
{
cout<<"factors are";
for(i=2;i<num/2;i++)
if(num%i==0)
cout<<i<<",";
}
getch();
}

Is This Answer Correct ?    30 Yes 19 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

output for printf("printf");

1977


write a program to calculate the amount of investment after a period n years if the principal investors was p and interest is calculated using compound interest,formular=a=p(1+r)^n

2364


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?

7330


how to write a program that opens a file and display in reverse order?

2561


Write a simple encryption program using string function which apply the substitution method.

5531






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.

2061


write a function that allocates memory for a single data type passed as a parameter.the function uses the new operator and return a pointer to the allocated memory.the function must catch and handle any exception during allocation

2394


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; }

639


write a program that can LOCATE and INSERT elements in array using c++ programming languages.

3431


can you please write a program for deadlock that can detect deadlock and to prevent deadlock.

2736


Given a table of the form: Product Sold on A 1/1/1980 B 1/1/1980 C 1/1/1980 A 1/1/1980 B 1/1/1980 C 2/1/1980 A 2/1/1980 There are 30 products and 10,000 records of such type. Also the month period during which sales happened is given to u. Write the program to display the result as: Product Month No. of copies A January 12 A February 15 A March 27 B January 54 B February 15 B March 10 C January 37

2042


write a program using virtual function to find the transposing of a square matrix?

2837


Teta-Omeg-Big-Oh Show that f(n) = n2 + 3n3 is ;(n3).

3186


write a program to convert temperature from fa height into celcius and vise versa,use modular programming

2434


How to Split Strings with Regex in Managed C++ Applications?

3120