cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
finding out if integer is multiple of 3
finding out if integer is multiple of 3
Mar 2, 2009 at 1:43pm UTC
bangura87
(15)
this is what i have so far. I need to modify this with arithmetic operators to find out whether or not the integer is a multiple of 3.
#include <iostream>
using namespace std;
int main()
{
int integer;
cout << "Enter number:";
cin >> integer;
if(integer < 0) cout << "This number is negative";
else cout << "This number is positive";
}
Mar 2, 2009 at 1:56pm UTC
jdd
(95)
This can be done very easily using the modulo (%) operator. It gives the
remainder of a division operation. So,
integer%3
will be zero if
integer is divisible by three.
http://www.cplusplus.com/doc/tutorial/operators.html
Last edited on
Mar 2, 2009 at 2:14pm UTC
Topic archived. No new replies allowed.