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
We can combine more than one variable on the same line i.e.   float number1,number2,number3; etc Sometimes we want to mix the variable types used on the same line, this could

Write a recursive function recursiveMin that takes an integer array, a starting subscript and an ending subscript as arguments, and returns the smallest element in the array. The

A: It allows a program to reference an identifier in global scope which has been hidden by another identifier along with the same name in the local scope.

Unions A union is also like a structure, except that only single variable in the union is stored in the allocated memory at a time. It is a collection of mutually exclusive var

Problem: a) Give and Illustrate with the help of diagrams, four topologies for the Network Information System (NIS). b) Give methods for creating user accounts and groups.


This program requires the use of a windows box, no console applications are allowed. Prepare for Christmas now.  Each year, Reindeer Gift Emporium publishes a Christmas price list

A: Method of passing arguments to a function that takes parameter of type reference.  for instance: void swap( int & x, int &amp;amp; y ) { int temp = x; x =


coloring of elements in matrix form inm particular matrix.the color should not match with another color.