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
//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 |
Answer / beena
#include <iostream>
using namespace std;
void prime_num(int);
int main()
{
cout << " Enter a number ";
int num = 0;
cin >> num;
if((num/100>0)&&(num/100<10))
printf("\nNumber is of 3 Digits");
else
printf("\nNot a 3 digit number");
bool flag = prime_num(num);
if(!flag)
{
printf("\nNumber %d is not a prime",n);
printf("\nIts factors are:\n\t");
x=2;
while(num!=1)
{
while(num%x==0)
{
num=num/x;
printf("%d ",x);
}
x++;
}
}
}
bool prime_num( int num)
{
bool isPrime=true;
int checkNum = 1;
for(int i = 1; i <=num; i++)
checkNum *= 2;
checkNum +=1;
for ( int i = 0; i <= checkNum; i++)
{
for ( int j = 2; j <= checkNum; j++)
{
if ( i!=j && i % j == 0 )
{
isPrime=false;
break;
}
}
if (isPrime)
{
cout <<"Prime:"<< i << endl;
}
isPrime=true;
}
return isPrime;
}
Is This Answer Correct ? | 5 Yes | 5 No |
#include<iostream>
#include<stdlib.h>
#include<math.h>
using namespace std;
int main()
{
int n,a[100];
cout<<"Enter size of the array"<<endl;
cin>>n;
cout<<"Enter the any value in 3digit format"<<endl;
for (int i=0;i<n;i++)
cin>>a[i];
for (int i=0;i<n;++i)
{
if((a[i]/100)>10)
{
cout<<"invaild"<<endl;
exit(0);
}
}
cout<<"Vaild within 3idigit number"<<endl;
int temp=pow(2,a[n-1]);
temp=temp+1;
cout<<temp;
int count=0;
for(int i=1;i<=1000;i++)
if( (temp)%i == 0 )
{
count++;
}
if (count==2)
{
cout<<endl<<temp<<"-->%2^n+1%"<<"is prime number"<<endl;
}
else
{
cout<<endl<<temp<<" is not primre number
";
}
return 0;
}
Is This Answer Correct ? | 0 Yes | 0 No |
can we declare an object of a class in another class?(assume both class as public classes)
How can I Draw an ellipse in 3d space and color it by using graph3d?
. Write a program using two-dimensional arrays that computes the sum of data in tows and the sum of data in columns of the 3x3 (three by three) array variable n[3][3].
write a program to perform generic sort in arrays?
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+……………...
how to diplay a external image of output on winxp by using c & c++,
swap prog
what is the best algorithm to sort out unique words from a list of more than 10 million words(1 crore+)? we need the best technique in the terms of execution time.
#include<iostream.h> //main() //{ class A { friend class B; public: void read(); }; class B { public : int a,b; }; void A::read() { cout<<"welcome"; } main() { A x; B y; y.read(); } In the above program......, as B is a friend of A B can have access to all members,i cant access y.read . could you please tell me the reason and what would i code to execute this program?
Write a program to enter 10 number of integer entries into an array n and then odds up all the odd entries. the program then displays the result. plssss answer assss fast asss u can...
using friend function find the maximum number from given two numbers from two different classes.write all necessary functions and constructor for the classes.
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!!!)