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 / sreejesh1987
//Sorry, this code is wrong
//but'll be useful for some other logic
#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);
}
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 ? | 16 Yes | 6 No |
Post New Answer View All Answers
how to write a program that opens a file and display in reverse order?
write a function that reverse the elements of an array in place.The function must accept only one pointer value and return void.
write a program to convert temperature from fa height into celcius and vise versa,use modular programming
3. Program to find the Sum of give series. a. (1)+(1+2)+(1+2+3)+(1+2+3+4)+……………………………….. b. 1/1+1/9+1/25+1/49+……………...
Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.
write a function that allocates memory for a single data type passed as a parameter.the function uses the new operator and return a pointer to the allocated memory.the function must catch and handle any exception during allocation
Code for Method of Handling Factorials of Any Size?
write a program that creates a sequenced array of numbers starting with 1 and alternately add 1 and then 2 to create the text number in the series , as shown below. 1,33,4,6,7,9,............147,148,150 Then , using a binary search , searches the array 100 times using randomly generated targets in the range of 1 to 150
Create a program to read two random data set in two files named data1.txt and data2.txt manifold contains integer numbers, whereas data2.txt file contains the float type numbers. Simpanlahmasing each into 2 pieces of data that is an array of type integer array and an array of type float, then calculate the average numbers in the second array.
create a stucture student containing field for roll no,class,year and marks.create 10 student annd store them in a file
what mean void creat_object?in public class in this code class A{ public: int x; A(){ cout << endl<< "Constructor A";} ~A(){ cout << endl<< "Destructor A, x is\t"<< x;} }; void create_object(); void main() { A a; a.x=10; { A c; c.x=20; } create_object(); } void create_object() { A b; b.x=30; }
Teta-Omeg-Big-Oh Show that f(n) = n2 + 3n3 is ;(n3).
How to Split Strings with Regex in Managed C++ Applications?
write a program using virtual function to find the transposing of a square matrix?
What output does this program generate as shown? Why? class A { A() { cout << "A::A()" << endl; } ~A() { cout << "A::~A()" << endl; throw "A::exception"; } }; class B { B() { cout << "B::B()" << endl; throw "B::exception"; } ~B() { cout << "B::~B()"; } }; int main(int, char**) { try { cout << "Entering try...catch block" << endl; A objectA; B objectB; cout << "Exiting try...catch block" << endl; } catch (char* ex) { cout << ex << endl; } return 0; }