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 |
What is sizeof return in c?
Explain can you assign a different address to an array tag?
plz let me know how to become a telecom protocol tester. thank you.
please give me a VIRTUSA sample palcement papers.... you will only send TECHNICAL SECTION..... that is help for me Advance Thanks........................
how to execute with out main in cprogram
difference between memcpy and strcpy
write a program to find the sum of the array elements in c language?
24 Answers ICT, Infosys, Wipro,
Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL
two progs are given. one starts counting frm 0 to MAX and the other stars frm MAX to 0. which one executes fast.
how to compare two strings without using strcmp() function??
code for reverse alternate words from astring
How does free() know how many bytes to free?