Write a program that will find out whether the given number is even or odd. If odd number then whether it is prime or not.
PROGRAM:
#include <iostream.h>
#include <conio.h>
void main() {
clrscr();
int num,flag=0;
cout<<"Enter the number to find odd or even: ";
cin>>num;
if((num%2)==0) {
cout<<num<<" is even\n";
}//end of if
else {
cout<<num<<" is odd\n";
for(int i=3;i<=7;i+=2) {
if(num%i==0){
flag=1;
break;
}
}//end of for
if(flag==1)
cout<<num<<" is not a prime number\n";
else
cout<<num<<" is a prime number\n";
}//end of else
getch();
}//end of the program
Monday, May 5, 2008
program to find even or odd number, prime number or not
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment