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

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n, i, m=0, flag=0;
cout << "Enter the power of 2 ";
cin >> n;
m=pow(2,n)+1;
for(i = 2; i <= m; i++)
{
if(m % i == 0)
{
cout<<"Number is not Prime."<<endl;
flag=1;
break;
}
}
if (flag==0)
cout << "Number is Prime."<<endl;
return 0;
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

create a stucture student containing field for roll no,class,year and marks.create 10 student annd store them in a file

2220


write a program that reverses the input number of n.Formulate an equation to come up with the answer.

7041


write a function that reverse the elements of an array in place.The function must accept only one pointer value and return void.

3958


Write a C++ program without using any loop (if, for, while etc) to print prime numbers from 1 to 100 and 100 to 1 (Do not use 200 print statements!!!)

3274


A suduco given & u hv 2 check if it is incomplete(blanks left),or correct or incorrect

2407






what mean void creat_object?in public class in this code class A{ public: int x; A(){ cout << endl<< "Constructor A";} ~A(){ cout << endl<< "Destructor A, x is\t"<< x;} }; void create_object(); void main() { A a; a.x=10; { A c; c.x=20; } create_object(); } void create_object() { A b; b.x=30; }

2069


write a program using 2 D that searches a number and display the number of items 12 inputs values input 15,20, 13, 30, 38, 40,16, 18, 20 ,18 ,20 enter no. to search : 20

3368


Write a program that print in screen a tree with its height taken from user by entering number of 4 digits and find the odd numbers then calculate the sum of odd numbers so he get the height of tree?

2915


solve the problem in the programming language C++"if a five digit number is input through the keyboard.Write a program to calculate the sum of its digits(hint: use the modulus operator)

2937


i don't know about working of nested for loop can any one help me

1794


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

2845


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

3129


How to swap two ASCII numbers?

2451


write a program that reads a series of strings and prints only those strings begging with letter "b"

2674


Definition of priority queue was given. We have to implement the priority queue using array of pointers with the priorities given in the range 1..n. The array could be accessed using the variable top. The list corresponding to the array elements contains the items having the priority as the array index. Adding an item would require changing the value of top if it has higher priority than top. Extracting an item would require deleting the first element from the corresponding queue. The following class was given: class PriorityQueue { int *Data[100]; int top; public: void put(int item, int priority); // inserts the item with the given priority. int get(int priority); // extract the element with the given priority. int count(); // returns the total elements in the priority queue. int isEmpty(); // check whether the priority queue is empty or not. }; We had to implement all these class functions.

4398