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
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 |
Does c have enums?
what is difference between getchar,putchar functions and printf and scanf function? does putchar show output only when input given to it
Explain how do you list files in a directory?
what is pointer
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); }
How many loops are there in c?
Write a Program to accept different goods with the number, price and date of purchase and display them
Is sizeof a keyword in c?
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.
What are pointers really good for, anyway?
what is difference between array of characters and string
what is a constant pointer in C