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
How to specify different memory sections for a variable using #Pragma?

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

i need amibroker afl to dll plugin

Program for calculate average of total marks: #include using namespace std; void print(int marks_arr[],int cnt) { int ind[cnt]; int i=0; int j=0; int k=0;

example of padovan string program

create algorithm for doubly link list using c data structure

In this worksheet you are asked to write three classes in C++: Lecture class, Course class and University class. The classes relate to each other in the way that a Course has many

Deliverables: you are required to upload your c code in the assignment dropbox set in Moodle. You are supposed to work with Linux gcc compiler and pico editor for compiling via the

#include #include using namespace std; class Book { private: string title; int iD; int year_pub; string author; public: string getTitle(); int getId(); int getYear_Pub(); st

A string S is said to be "Super ASCII", if it contains the character frequency equal to their ascii values. String will contain only lower case alphabets (''a''-''z'') and the asci