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 |
When a c file is executed there are many files that are automatically opened what are they files?
code for selection sort?
What does *p++ do?
what is array?
Why pointers are used in c?
What is the difference between constant pointer and constant variable?
What is diffrance between declaration and defination of a variable or function
A character flag or control mechanism that delineates one data item from another a) variable b) constant c) delimiter d) call by reference
What is a built-in function in C?
What are header files and what are its uses in C programming?
How can I write a function analogous to scanf?
What is pointer in c?