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

#include<iostream>
#include<stdlib.h>
#include<math.h>
using namespace std;

int main()
{

int n,a[100];
cout<<"Enter size of the array"<<endl;
cin>>n;

cout<<"Enter the any value in 3digit format"<<endl;
for (int i=0;i<n;i++)
cin>>a[i];

for (int i=0;i<n;++i)
{

if((a[i]/100)>10)
{
cout<<"invaild"<<endl;
exit(0);
}
}

cout<<"Vaild within 3idigit number"<<endl;


int temp=pow(2,a[n-1]);
temp=temp+1;
cout<<temp;
int count=0;
for(int i=1;i<=1000;i++)
if( (temp)%i == 0 )

{
count++;
}


if (count==2)
{
cout<<endl<<temp<<"-->%2^n+1%"<<"is prime number"<<endl;
}
else
{
cout<<endl<<temp<<" is not primre number
";
}


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

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

2567


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 C/C++ program that connects to a MySQL server and displays the global TIMEZONE.

4579


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

2198


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

2407






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

2441


How can I Draw an ellipse in 3d space and color it by using graph3d?

2138


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

7041


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


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

3128


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.

3397


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


output for printf("printf");

1985


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

2220


3. Program to find the Sum of give series. a. (1)+(1+2)+(1+2+3)+(1+2+3+4)+……………………………….. b. 1/1+1/9+1/25+1/49+……………...

4355