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


Please Help Members By Posting Answers For Below Questions

What is #line in c?

554


What is meant by type casting?

618


What are pointers really good for, anyway?

608


How can I find out the size of a file, prior to reading it in?

614


What is the role of && operator in a program code?

564






How can a program be made to print the line number where an error occurs?

642


What is the difference between local variable and global variable in c?

679


What is sizeof array?

602


"C" language developed by "Dennis Ritchie" at AT & T. his remarks are a) too general, too abstract b) could deal with only specific problems c) lost generality of BCPL and B restored d) no remarks

652


What are the 5 data types?

594


What are the usage of pointer in c?

700


How can I do peek and poke in c?

611


How can variables be characterized?

1639


If a variable is a pointer to a structure, then which operator is used to access data members of the structure through the pointer variable?

771


What is pass by reference in c?

603