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
int main() { Int n=20,i; For(i=0;i<=n;i--) { Printf(“-“); Return 0;
What is ctrl c called?
If you know then define #pragma?
What are the functions to open and close file in c language?
What is the difference between break and continue?
Write a program to generate the Fibinocci Series
What is indirection? How many levels of pointers can you have?
I came across some code that puts a (void) cast before each call to printf. Why?
Which header file is used for clrscr?
What is a union?
Explain can static variables be declared in a header file?
How pointers are declared?
What is call by value in c?
What does the characters “r” and “w” mean when writing programs that will make use of files?
What is derived datatype in c?