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
Node *orderedInsert(Node *p, int newval); /* Allocates a new Node with data value newval and inserts into the ordered list with first node pointer p in such a way that the data va

In this we will take a closer look at the logic behind Object Oriented Programming.  Read through the pseudocode listed below and answer the following questions. Class Square

A: C++, unlike only about every other language with exceptions, is extremely accomodating while it comes to what you can throw. Actually, you can throw anything you akin to. That b


#decode the code

Linear search in array - C program: Write a program in c to define a linear search in array. void main()                 {                 clrscr();

WHAT IS A C LANGUAGE? C IS A PROGRAMMING?

It is a class defined in the scope of a function _ any function, whether a member functions or a free function. For instance: // Example : Local class // int f() { c

Compiler Design - Limit In The Method Instructions

//Create a custom calculator program capable of reading the input stream of an expression //and make basic computations to provide answer. //Your program will ask the user to