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 / 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 |
Post New Answer View All Answers
how to diplay a external image of output on winxp by using c & c++,
write a program that prompt the user to enter his height and weight,then calculate the body mass index and show the algorithm used
We need to write the function to check the password entered is correct or not based on the following conditions.. a) It must have atleast one lower case character and one digit. b)It must not have any Upper case characters and any special characters c) length should be b/w 5-12. d) It should not have any same immediate patterns like abcanan1 : not acceptable coz of an an pattern abc11se: not acceptable, coz of pattern 11 123sd123 : acceptable, as not immediate pattern adfasdsdf : not acceptable, as no digits Aasdfasd12: not acceptable, as have uppercase character
How to swap two ASCII numbers?
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+……………...
write a program using virtual function to find the transposing of a square matrix?
Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.
A suduco given & u hv 2 check if it is incomplete(blanks left),or correct or incorrect
How can I Draw an ellipse in 3d space and color it by using graph3d?
i don't know about working of nested for loop can any one help me
write a program to convert temperature from fa height into celcius and vise versa,use modular programming
how to write a program that opens a file and display in reverse order?
how to take time as input in the format (12:02:13) from user so that controls remains between these columns?
write a program that can LOCATE and INSERT elements in array using c++ programming languages.
write a program to calculate the amount of investment after a period n years if the principal investors was p and interest is calculated using compound interest,formular=a=p(1+r)^n