5) 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.without using big int and exponential function



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

Answer / sreejesh1987

#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 ?    3 Yes 0 No

Post New Answer

More C Interview Questions

Does c have enums?

0 Answers  


what is difference between getchar,putchar functions and printf and scanf function? does putchar show output only when input given to it

5 Answers   DIT,


Explain how do you list files in a directory?

0 Answers  


what is pointer

1 Answers   TCS,


what would be the output of the following prog? Justify your answer? main() { unsigned char ch; unsigned char i; ch = -255; printf("%d",ch); i = -1; printf("%d",i); }

1 Answers  






How many loops are there in c?

0 Answers  


Write a Program to accept different goods with the number, price and date of purchase and display them

0 Answers   HDFC,


Is sizeof a keyword in c?

0 Answers  


write a program in c language that uses function to locate and return the smallest and largest integers in an array,number and their position in the array. it should also find and return the range of the numbers , that is , the difference between the largest number and the smallest.

1 Answers  


What are pointers really good for, anyway?

0 Answers  


what is difference between array of characters and string

18 Answers   Accenture, Nest,


what is a constant pointer in C

0 Answers  


Categories