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 / ram khilawan
#include<iostream.h>
#include<conio.h>
int main()
{
int i,n,num,p=1;
cout<<"enter the number";
cin>>n;
num=pow(2,n)+1;
for(i=2;i<num/2;i++)
{
if(num%i==0)
{
p=0;
break;
}
}
if(p==1)
cout<<"prime";
else if(p==0)
{
cout<<"factors are";
for(i=2;i<num/2;i++)
if(num%i==0)
cout<<i<<",";
}
getch();
}
| Is This Answer Correct ? | 7 Yes | 4 No |
Post New Answer View All Answers
how to take time as input in the format (12:02:13) from user so that controls remains between these columns?
output for printf("printf");
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
i really need help about this.. write a program to display the set of odd and even numbers separately. find the highest and lowest value of the given numbers.
Write a (n) algorithm that sorts n distinct integers, ranging in size between 1 and kn inclusive, where k is a constant positive integer. (Hint: Use a kn-element array.)
Write a simple encryption program using string function which apply the substitution method.
Given a table of the form: Product Sold on A 1/1/1980 B 1/1/1980 C 1/1/1980 A 1/1/1980 B 1/1/1980 C 2/1/1980 A 2/1/1980 There are 30 products and 10,000 records of such type. Also the month period during which sales happened is given to u. Write the program to display the result as: Product Month No. of copies A January 12 A February 15 A March 27 B January 54 B February 15 B March 10 C January 37
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 program that can LOCATE and INSERT elements in array using c++ programming languages.
How can I Draw an ellipse in 3d space and color it by using graph3d?
Code for Method of Handling Factorials of Any Size?
write a program using 2 D that searches a number and display the number of items 12 inputs values input 15,20, 13, 30, 38, 40,16, 18, 20 ,18 ,20 enter no. to search : 20
Write a C/C++ program that connects to a MySQL server and displays the global TIMEZONE.
Given a table of the form: Product Sold on A 1/1/1980 B 1/1/1980 C 1/1/1980 A 1/1/1980 B 1/1/1980 C 2/1/1980 A 2/1/1980 There are 30 products and 10,000 records of such type. Also the month period during which sales happened is given to u. Write the program to display the result as: Product Month No. of copies A January 12 A February 15 A March 27 B January 54 B February 15 B March 10 C January 37
i don't know about working of nested for loop can any one help me