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
How can a string be converted to a number?
If errno contains a nonzero number, is there an error?
#define f(g,h) g##h main O int i=0 int var=100 ; print f ("%d"f(var,10));} wat would be the output??
Why functions are used in c?
Write a program to show the change in position of a cursor using c
How can I automatically locate a programs configuration files in the same directory as the executable?
What is the size of a union variable?
Why static is used in c?
What is typeof in c?
How a string is stored in c?
What is uint8 in c?
What is the best way of making my program efficient?
What are type modifiers in c?
What are the loops in c?
How will you delete a node in DLL?