Toggle navigation
Home
Latest pastes
FAQ
Random
BitBin is shutting down!
Register
Login
Number
SUBMITTED BY:
Guest
DATE:
Feb. 7, 2014, 1:39 p.m.
FORMAT:
C++
SIZE:
996 Bytes
Raw
Download
Tweet
HITS:
681
Go to comments
Report
#include
<iostream>
using
namespace
std
;
class
number
{
private
:
int
value
;
public
:
number
(
int
x
){
value
=
x
;}
bool
isPrime
();
bool
isOdd
();
long
long
factorial
();
};
bool
number::isPrime
()
{
int
a
;
int
n
=
value
;
if
(
n
<=
1
)
return
false
;
for
(
a
=
2
;
a
<
n
;
a
++
)
if
(
n
%
a
==
0
)
return
false
;
return
true
;
}
bool
number::isOdd
()
{
if
(
value
%
2
==
0
)
return
false
;
else
return
true
;
}
long
long
number::factorial
()
{
int
i
;
long
long
factValue
=
1
;
for
(
i
=
1
;
i
<=
value
;
i
++
)
{
factValue
=
factValue
*
i
;
}
return
factValue
;
}
int
main
()
{
int
x
;
cout
<<
"Enter an interger(Must be greater than 0): "
;
cin
>>
x
;
number
a
(
x
);
if
(
a
.
isPrime
()
==
true
)
cout
<<
"Prime"
<<
endl
;
else
cout
<<
"Not Prime"
<<
endl
;
if
(
a
.
isOdd
()
==
true
)
cout
<<
"Odd"
<<
endl
;
else
cout
<<
"Even"
<<
endl
;
cout
<<
"Factorial: "
<<
a
.
factorial
()
<<
endl
;
return
0
;
}
Please enable JavaScript to view the
comments powered by Disqus.
comments powered by
Disqus