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 / srinivasu
i have written in java
import java.io.*;
public class ThreeDigit
{
public static void main(String args[])throws IOException
{
double t=1;
DataInputStream ds=new DataInputStream(System.in);
System.out.print("Enter Three Digit Number");
int n=Integer.parseInt(ds.readLine());
int k=0;
for(int i=1;i<=n;i++)
{
t=t*2;
}
t=t+1;
int x=2;
do
{
if(t%x==0)
{
System.out.println("The 2^n+1 of given 3 digit
number" +t+ "is not prime");
System.out.println("The factors for" +t+ "are:");
for(int p=1;p<=t;p++)
{
if(t%p==0)
{k++;
System.out.println("The"+k+"factor is"+p);
}
}
System.exit(0);
}
x++;
}while(x<t);
System.out.println("The 2^n+1 number"+t+"is prime");
System.exit(0);
}
}
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
to find the closest pair
how to execute a program using if else condition and the output should enter number and the number is odd only...
What is an expression?
What are header files and explain what are its uses in c programming?
What does %c do in c?
Can you explain the four storage classes in C?
What is void main ()?
What is a good way to implement complex numbers in c?
When should I declare a function?
What is a double c?
Write the test cases for checking a variable having value in range -10.0 to +10.0?
please explain clearly about execution of c program in detail,in which stage are the printf sacnf getting into exeecutable code
What is call by value in c?
Are pointers integers in c?
1) write a program to generate 1st n fibonacci prime numbers using Nested if 2) write a program to generate twin prime numbers from m to n using nested if 3) write a program to check whether a given integer is a strong number or not using nested if 4) Write a program to generate prime factors of a given integer using nested if 5)write a program to generate prime numbers from m to n using nested if 6)write a program to generate perfect numbers from m to n using nested if 7)write a program to generate the pallindromes from m to n using neste if 8)write a program to generate armstrong numbers from m to n using nested if 9)write a program to generate strong numbers from m to n using nested if