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
What is #line in c?
What is meant by type casting?
What are pointers really good for, anyway?
How can I find out the size of a file, prior to reading it in?
What is the role of && operator in a program code?
How can a program be made to print the line number where an error occurs?
What is the difference between local variable and global variable in c?
What is sizeof array?
"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
What are the 5 data types?
What are the usage of pointer in c?
How can I do peek and poke in c?
How can variables be characterized?
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?
What is pass by reference in c?