View Single Post
  #1  
Old 01-03-2011, 02:39 PM
bonfire's Avatar
bonfire bonfire is offline
M.Arsalan Qureshi

 
Join Date: Oct 2008
Location: Garden Town, Multan Cantt
Posts: 616
Program / Discipline: BSTS
Class Roll Number: 09-31
bonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond repute
Default Program to enter an integer and print if it is prime or composite

Program to enter an integer and print if it is prime or composite

#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;
getch();
exit(0);
}
else
{
cout << num1 << " is a prime number." << endl;
getch();
exit(0);
}
}
}
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.

Sample Input
23
Sample Output
23 is a prime number.

__________________

Reply With Quote