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..

Answer / makthar basha

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.

Is This Answer Correct ?    64 Yes 22 No

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

Answer / sreenu

please send source code for for 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 in c.

Is This Answer Correct ?    25 Yes 16 No

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

Answer / salma

i also face sthe same question please send me the full code

Is This Answer Correct ?    10 Yes 7 No

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

Answer / sreejesh1987

//Sorry,this code is wrong.
//I'm not removing this,because it may serve some other purpose.

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n,x,flag=0,d;
clrscr();
printf("\tPRIME CHECK\n");
printf("Enter a 3digit no:");
scanf("%d",&n);

if((n/100>0)&&(n/100<10))
printf("\nNumber is of 3 Digits");
else
printf("\nNot a 3 digit number");

for(j=2;j<n,n%j!=0;j++)
if(n-1==j)
{
printf("\n\t%d is a prime",n);

flag=1;

d=n-1;
while(d%2==0)
d=d/2;

if(d==1)
printf("\nNumber%d is in 2^n+1 format",n);
else
printf("\nNumber%d is not in 2^n+1 format",n);
}

if(!flag)
{
printf("\nNumber %d is not a prime",n);
printf("\nIts factors are:\n\t");

x=2;
while(n!=1)
{
while(n%x==0)
{
n=n/x;
printf("%d ",x);
}
x++;
}
}
getch();
}

Is This Answer Correct ?    6 Yes 3 No

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

Answer / amit

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n, i, m=0, flag=0;
cout << "Enter the power of 2 ";
cin >> n;
m=pow(2,n)+1;
for(i = 2; i <= m; i++)
{
if(m % i == 0)
{
cout<<"Number is not Prime."<<endl;
flag=1;
break;
}
}
if (flag==0)
cout << "Number is Prime."<<endl;
return 0;
}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ Code Interview Questions

can we declare an object of a class in another class?(assume both class as public classes)

1 Answers   Microsoft,


Write an algorithm that receives a string and reverses it.

2 Answers  


write a program that calculate the volume of cylinder after user enters radius and height and show the algorithm used

1 Answers   Jomo Kenyatta University,


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.

3 Answers   TCS, Vimukti Technologies, Wipro,


Write a program that print in screen a tree with its height taken from user by entering number of 4 digits and find the odd numbers then calculate the sum of odd numbers so he get the height of tree?

0 Answers  






1+1/2!+1/3!+...+1/n!

0 Answers  


How to swap two ASCII numbers?

0 Answers  


Code for Small C++ Class to Transform Any Static Control into a Hyperlink Control?

0 Answers   Wipro,


Given 1 to n distinct random number of which n+1th element was duplicated. How do find the duplicate element and explain the time complexity of the algorithm.

0 Answers   Microsoft, NetApp,


Write a C++ program without using any loop (if, for, while etc) to print prime numbers from 1 to 100 and 100 to 1 (Do not use 200 print statements!!!)

0 Answers   iGate,


PROBLEM #8 The cashier at the counter of a Super Store, Mr. Khazaanchi has the following bundles of rupee cash notes with him: Rs. 1, 2, 5, 10, 50, 100, 500, 1000 A customer comes at his counter with various items that he has shopped. Mr. Khazaanchi totals the item prices and tells the customer his total amount payable. The customer gives Mr. Khazanchi some amount of cash. Find the total number of rupee notes of each denomination (i.e. 1, 2, 5, 10, 50, 100, 500, 1000) Mr. Khazaanchi will have to give to the withdrawer ensuring that the total number of rupee notes are minimum.

1 Answers   AR, ARJ,


main(){int a=5,b 10,c=2, d;a=b c;d=++a=(--c)*2; printf("%d%d%d%d,a,b,c,d; return o;}

1 Answers  


Categories