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
Answer Posted / nitin garg
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
int num,i,sum=1,flag=0;
printf("enter three digit no
");
scanf("%d",&num);
for(i=1;i<=num;i++)
{
sum=sum*2;
}
sum++;
printf("
%d",sum);
for(i=2;i<sum/2;i++)
{
if(sum%i==0)
flag=1;
}
if(flag==0)
printf("
number is prime");
printf("
factor is below:
");
for(i=1;i<=sum;i++)
{
if(sum%i==0)
printf("%d ",i);
}
getch();
return 0;
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Where static variables are stored in memory in c?
Can main () be called recursively?
What is wrong with this program statement? void = 10;
What is && in c programming?
What is the difference between exit() and _exit() function in c?
What is indirection? How many levels of pointers can you have?
Can you apply link and association interchangeably?
Who is the main contributor in designing the c language after dennis ritchie?
What does c mean in standard form?
What is c programing language?
Which is better malloc or calloc?
praagnovation
What is the difference between printf and scanf in c?
Why shouldn’t I start variable names with underscores?
What does a derived class inherit from a base class a) Only the Public members of the base class b) Only the Protected members of the base class c) Both the Public and the Protected members of the base class d) .c file