OOPc using C++

With this blog I want to share my knowledge of OOPs and C++. I Hope this can quench your thirst for learning.Any suggestions and comments are welcome.
Showing posts with label Prime or composite. Show all posts
Showing posts with label Prime or composite. Show all posts

Tuesday, August 3, 2010

Program 3- Program to find if the number is prime or composite.


This program takes in an integer num1 as a screen input from the user.
It then determines whether the integer is prime or composite.
It finally outputs the approriate message by writing to the 'cout' stream.

#include <iostream.h>
#include <conio.h>
#include <process.h>

void main()
{
            clrscr();
            int num1,x;
            cout << "Enter an integer : " << endl;
            cin>>num1;
            for(x=2;x<num1;x++)
                 {
                      if(num1%x==0)
                          {
                             cout << num1 << " is a composite number." << endl;
                           }
                      else
                          {
                             cout << num1 << " is a prime number." << endl;                                            
                           }
                      }

 getch();
 exit(0);
}

Sample Input:
21

Sample Output:
21 is a composite number.