Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Write a program to find whether the given number is prime or
not?

Answer Posted / naman patidar

we can reduce no of iterations by changing the condition
(i<=n/2) with (i<=sqrt(n))..
This is a rule that if a number is not dividable by any no
(except 1)less than equal to the sqr root of it then the no
is prime.

int n ; // any no, user input.
int i ;
for(i=2; i<=sqrt(n); i++ )
{
if(n%i==0)
{
printf("not prime");
break;
}
}
if(i > sqrt(n)) // you can use a flag as well here
{
printf("prime no");
}

Is This Answer Correct ?    7 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the types of type qualifiers in c?

1034


what is a constant pointer in C

1098


application areas a 'c' a) operating system b) graphics, interpreter, assembler c) program evalution, communication softwares d) all the above

1016


Explain how can I open a file so that other programs can update it at the same time?

1058


What is static function in c?

1068


State two uses of pointers in C?

1011


what is the difference between north western polytechnique university and your applied colleges?? please give ur answers for this. :)

2345


What are multibyte characters?

1063


What does sizeof return c?

1015


how do you programme Carrier Sense Multiple Access

1928


What are linked lists in c?

1088


What is operator precedence?

1152


Define the scope of static variables.

1067


Are the outer parentheses in return statements really optional?

1054


Program to find the sum of digits of a given number until the sum becomes a single digit. (e.g. 12345=>1+2+3+4+5=15=>1+5=6)

1102