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.

Answers were Sorted based on User's Feedback



Write a program that takes a 3 digit number n and finds out whether the number 2^n + 1 is prime, or..

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

Write a program that takes a 3 digit number n and finds out whether the number 2^n + 1 is prime, or..

Answer / ram khilawan

#include<iostream.h>
#include<conio.h>

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 ?    7 Yes 4 No

Post New Answer

More C++ Code Interview Questions

what is the use of using for loop as "for(;;)"?

5 Answers   Satyam,


Find the maximum product of three numbers in an array? Eg. 9,5,1,2,3 Max product= 9*5*3= 135 The array can hav negative numbers also..

7 Answers   CTS,


Perform the functionality of 2-D array through 1-D array and in it the functions to be performed were: (1) Display the array in 2-D format (2) Display a particular element (3) Display a particular row (4) Display a particular column

1 Answers   Nagarro,


Write a program to enter 10 number of integer entries into an array n and then odds up all the odd entries. the program then displays the result. plssss answer assss fast asss u can...

1 Answers  


write a function – oriented program that calculates the sum of the squares from 1 to n. thus, if the input is 3, the output is 14

3 Answers  






Given 1 to n distinct random number of which n+1th element was duplicated. How do find the duplicate element and explain the time complexity of the algorithm.

0 Answers   Microsoft, NetApp,


. Write a program using two-dimensional arrays that computes the sum of data in tows and the sum of data in columns of the 3x3 (three by three) array variable n[3][3].

2 Answers   IBM,


write a program that can locate elements in array.

1 Answers  


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

0 Answers   Jomo Kenyatta University,


How do I store linked list datas into an array?

1 Answers  


readers and writers problem

1 Answers   Cognizant,


Write a &#61521;(n) algorithm that sorts n distinct integers, ranging in size between 1 and kn inclusive, where k is a constant positive integer. (Hint: Use a kn-element array.)

0 Answers  


Categories