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
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 |
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 |
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 |
What do you mean by team??
#include<stdio.h> main() { char *p1; char *p2; p1=(char *) malloc(25); p2=(char *) malloc(25); strcpy(p1,"Ramco"); strcpy(p2,"Systems"); strcat(p1,p2); printf("%s",p1); } Tell me the output?
What are the types of type specifiers?
What are integer variable, floating-point variable and character variable?
hi to every one .. how to view table pool after creating the pooled table? plz help me.. if any knows abt this ..
There seem to be a few missing operators ..
how to write a program which adds two numbers without using semicolon in c
a=0; b=(a=0)?2:3; a) What will be the value of b? why b) If in 1st stmt a=0 is replaced by -1, b=? c) If in second stmt a=0 is replaced by -1, b=?
Explain what could possibly be the problem if a valid function name such as tolower() is being reported by the c compiler as undefined?
Can you think of a way when a program crashed before reaching main? If yes how?
What is the difference between printf and scanf )?
which of the following is not a character constant a) 'thank you' b) 'enter values of p, n ,r' c) '23.56E-o3' d) all of the above