Write a C++ program that will check whether the last digit of any integer number is divisible by 3 or not by taking user input.

Code: 
#include <iostream>

using namespace std;

int main(){
    int x;

    cout << "Enter the Number: ";
    cin >> x;

    x %=10;

    if (x%3==0)
        cout << "Divisible";
    else
        cout << "Not Divisible";
}

Output: 
Enter the Number: 21
Not Divisible
Process returned 0 (0x0)   execution time : 4.639 s
Press any key to continue.

أحدث أقدم