C program to check prime numbers , C/C++ Programming

C Program to check PRIME NUMBERS

 

main()

{

          int i,k,r,flag;

          clrscr();

          printf("ENTER THE NO. TO CHECK IT IS PRIME OR NOT: ");

          scanf("%d",&k);

          for(i=2;i<=k/2;i++)

 

          {

                   r=k%i;

                   if(r==0)

                             flag=0;

                   else

                             flag=1;

          }

          if(flag==1)

                   printf("THIS IS A PRIME NO.");

          else

                   printf("THIS IS NOT A PRIME NO.");

          getch();

}

 

OUTPUT :

 ENTER NO: 10

IT IS NOT A PRIME NO.

 

Posted Date: 9/10/2012 2:07:54 AM | Location : United States







Related Discussions:- C program to check prime numbers , Assignment Help, Ask Question on C program to check prime numbers , Get Answer, Expert's Help, C program to check prime numbers Discussions

Write discussion on C program to check prime numbers
Your posts are moderated
Related Questions
Explain the working of Array with Strings? A string is defined in C language as an array of characters. A null character (‘\0') is automatically added to the end of the charact

Armed with your function from above, we can do some interesting things. For instance, any pixel where the offsets are both zero is a pit (lower than all surrounding points) .

Smugglers are becoming very smart day by day. Now they have developed a new technique of sending their messages from one smuggler to another. In their new technology, they are send


It''s that spooky time of year when the dead walk the Earth, things go bump in the night, and the Centers for Disease Control (CDC) recognizes the need for zombie preparedness (


C program to print R diagonal triangle: #define rows 3 #define cols 3 void main() {                 int i=0,j=0;                 int arr[rows][cols];

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

Rules of Inheritance: Private members are not inherited; the members can be accessed only within its class. It cannot be used through the object. Protected members are

A palindrome is a string that reads the same from the both the ends. Given a string S convert it to a palindrome by doing character replacement. Your takes is to convert S to palin