Ch5_DivisibilityTest - cout<<"The sum of the...

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 << "The sum of the digits = " << sum << endl; if (sum % 3 == 0) cout << temp << " is divisible by 3" << endl; else cout << temp << " is not divisible by 3" << endl; if (sum % 9 == 0) cout << temp << " is divisible by 9" << endl; else cout << temp << " is not divisible by 9" << endl; }...
View Full Document

This note was uploaded on 03/08/2011 for the course CSIT 139 taught by Professor Duzut during the Spring '11 term at Los Angeles City College.

Ask a homework question - tutors are online