Ch5_DivisibilityTest - cout <<...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//Program: Divisibility test by 3 and 9 / #include <iostream> using namespace std; u int main() { int num, temp, sum; cout << "Enter a positive integer: "; cin >> num; cout << endl; temp = num; sum = 0; do { sum = sum + num % 10; //extract the last digit //and add it to sum num = num / 10; //remove the last digit } while (num > 0);
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: cout &lt;&lt; &quot;The sum of the digits = &quot; &lt;&lt; sum &lt;&lt; endl; if (sum % 3 == 0) cout &lt;&lt; temp &lt;&lt; &quot; is divisible by 3&quot; &lt;&lt; endl; else cout &lt;&lt; temp &lt;&lt; &quot; is not divisible by 3&quot; &lt;&lt; endl; if (sum % 9 == 0) cout &lt;&lt; temp &lt;&lt; &quot; is divisible by 9&quot; &lt;&lt; endl; else cout &lt;&lt; temp &lt;&lt; &quot; is not divisible by 9&quot; &lt;&lt; endl; }...
View Full Document

Ask a homework question - tutors are online