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


Please Help Members By Posting Answers For Below Questions

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

1967


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

2289


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.

4592


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

5709


write a program that creates a sequenced array of numbers starting with 1 and alternately add 1 and then 2 to create the text number in the series , as shown below. 1,33,4,6,7,9,............147,148,150 Then , using a binary search , searches the array 100 times using randomly generated targets in the range of 1 to 150

3420






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

3033


Create a program to read two random data set in two files named data1.txt and data2.txt manifold contains integer numbers, whereas data2.txt file contains the float type numbers. Simpanlahmasing each into 2 pieces of data that is an array of type integer array and an array of type float, then calculate the average numbers in the second array.

2316


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

2563


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

3509


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

2391


develop a program to calculate and print body mass index for 200 employees

2374


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

2181


Write a C/C++ program that connects to a MySQL server and displays the global TIMEZONE.

4719


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

3260


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?

7539