Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with the following assingment in C++ complier in Visual Studio. Writ

ID: 3886783 • Letter: I

Question

I need help with the following assingment in C++ complier in Visual Studio.

Write a program that uses a math shortcut to decide if an integer is divisible by 3. First sum the digits of the number. You’ll need a loop along with / and % operators to extract the digits. For example: 1234 is 1+2+3+4, which is 10.

If the sum is divisible by 3, then the entire number is divisible by 3. For example, 1234 has a digit sum of 10. Since 3 does not evenly divide into 10, 1234 is not divisible by 3.

You may assume the number is a nonnegative integer.

Sample Run #1: (the highlighted text is what the user types)

Number? 1234

Sum = 10

1234 is NOT divisible by 3

Sample Run #2: (the highlighted text is what the user types)

Number? 123

Sum = 6

123 is divisible by 3

Other Considerations:

Did you remember system(“PAUSE”)?

Did you include comments?

Did you use constants?

Did you use good variable names?

Do you have consistent indentation?

Did you remember system(“PAUSE”)?

Did you include comments?

Did you use constants?

Did you use good variable names?

Do you have consistent indentation?

Explanation / Answer

#include <iostream>

using namespace std;

int main()
{

int n, n1,sum = 0;
cout<<"Number? ";
cin >> n;
n1=n;
while(n1 > 0) {
sum = sum + (n1%10);
n1=n1/10;
}
if(sum % 3 == 0) {
cout<<n<<" is divisible by 3"<<endl;
} else {
cout<<n<<" is NOT divisible by 3"<<endl;
}
return 0;
}

Output: