how to find the given number is prime or not?

Answer Posted / arunkumar mt

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,n,flag=0;
clrscr();
printf("enter a number\n");
scanf("%d",&n);
for(i=2;i<=sqrt(n);i++)
{
if(n%i==0)
{
flag=1;
break;
}
}
if(flag==0)
{
printf("given number %d is prime",n);
}
else
{
printf("given number %d is not prime",n);
}
getch();
}

Is This Answer Correct ?    2 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is it cc or c in a letter?

567


What is the usage of the pointer in c?

606


A function can make the value of a variable available to another by a) declaring the variable as global variable b) Passing the variable as a parameter to the second function c) Either of the two methods in (A) and (B) d) binary stream

669


What is wrong with this initialization?

593


Why do we use header files in c?

584






What is the use of #define preprocessor in c?

618


how to print electricity bill according to following charges first 100 units -1rs per unit for next 200 units-1.50 rs per unit without using conditions

2725


how to capitalise first letter of each word in a given string?

1434


a construct the"else" part of "if" statement contains anoth "if else" statement is called a) if-else b) else-if-else c) if-else-if-else d) chain if/if-else-if

704


Who is the founder of c language?

686


Want to know how to write a 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.

1522


When do we get logical errors?

637


What is difference between union and structure in c?

579


Is there any possibility to create customized header file with c programming language?

626


Explain the use of fflush() function?

627