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

Answers were Sorted based on User's Feedback



Write a program that takes a 3 digit number n and finds out whether the number 2^n + 1 is prime, or..

Answer / 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

Write a program that takes a 3 digit number n and finds out whether the number 2^n + 1 is prime, or..

Answer / pradeep

I got this question in the test, and have to submit the
solution in 1day. Please help me out. :(

Is This Answer Correct ?    0 Yes 0 No

Write a program that takes a 3 digit number n and finds out whether the number 2^n + 1 is prime, or..

Answer / nitin garg

#include<stdio.h>
#include<conio.h>
#include<string.h>

int main()
{
int num,i,sum=1,flag=0;
printf("enter three digit no
");
scanf("%d",&num);

for(i=1;i<=num;i++)
{
sum=sum*2;
}
sum++;
printf("
%d",sum);

for(i=2;i<sum/2;i++)
{
if(sum%i==0)
flag=1;
}
if(flag==0)
printf("
number is prime");
printf("

factor is below:
");

for(i=1;i<=sum;i++)
{
if(sum%i==0)
printf("%d ",i);
}

getch();
return 0;
}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

What is dangling pointer in c?

0 Answers  


How do I get an accurate error status return from system on ms-dos?

0 Answers  


which one of follwoing will read a character from keyboard and store in c a)c=getc() b)c=getchar() c)c=getchar(stdin) d)getc(&c) e)none

7 Answers   Trident,


How do I create a directory? How do I remove a directory (and its contents)?

0 Answers  


How can I make sure that my program is the only one accessing a file?

0 Answers  


I need a sort of an approximate strcmp routine?

0 Answers  


a program that performs some preliminary processing in C, it acts upon certain directives that will affect how the compiler does its work a) compiler b) loader c) directive d) preprocessor

0 Answers  


Does c have class?

0 Answers  


Explain how can I read and write comma-delimited text?

0 Answers  


In scanf h is used for

4 Answers   BFL,


disply the following menu 1.Disply 2.Copy 3.Append; as per the menu do the file operations 4.Exit

0 Answers  


What do you know about the use of bit field?

0 Answers  


Categories