Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

How can a string be converted to a number?

1070


If errno contains a nonzero number, is there an error?

1433


#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??

2013


Why functions are used in c?

1199


Write a program to show the change in position of a cursor using c

1125


How can I automatically locate a programs configuration files in the same directory as the executable?

1237


What is the size of a union variable?

1100


Why static is used in c?

1147


What is typeof in c?

1064


How a string is stored in c?

1117


What is uint8 in c?

1165


What is the best way of making my program efficient?

1084


What are type modifiers in c?

1098


What are the loops in c?

1053


How will you delete a node in DLL?

1339