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 Posted / 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 View All Answers
if the area was hit by a virus and so the decrease in the population because of death was x/3 and the migration from other places increased a population by 2x then annually it had so many ppl. find our the population in the starting.
Why is main function so important?
What is a void pointer in c?
Given two strings S1 and S2. Delete from S2 all those characters which occur in S1 also and finally create a clean S2 with the relevant characters deleted.
What is the easiest sorting method to use?
Is this program statement valid? INT = 10.50;
What is a string?
What is the difference between formatted&unformatted i/o functions?
What are header files in c programming?
What does node * mean?
What is the ANSI C Standard?
Was 2000 a leap year?
Do you know what are bitwise shift operators in c programming?
What is static and volatile in c?
What is a program flowchart and how does it help in writing a program?