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
Write a simple encryption program using string function which apply the substitution method.
write a program using virtual function to find the transposing of a square matrix?
find level of following tree (state, parent) " J,D I,D H,C E,B F,B G,C B,A D,A C,A A,& K,E L,E L,F M,F N,G O,H P,I P,H Q,I R,J S,K U,P T,L
write a program that can LOCATE and INSERT elements in array using c++ programming languages.
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)
Code for Easily Using Hash Table?
write a program that reads a series of strings and prints only those strings begging with letter "b"
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?
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
Write a C/C++ program that connects to a MySQL server and displays the global TIMEZONE.
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
A suduco given & u hv 2 check if it is incomplete(blanks left),or correct or incorrect
write a program that prompt the user to enter his height and weight,then calculate the body mass index and show the algorithm used
write a program to convert temperature from fa height into celcius and vise versa,use modular programming
develop a program to calculate and print body mass index for 200 employees