Divisibility

You are provided an array  A of the size N that contains non-negative integers. Your task is to determine whether the number that is formed by selecting the last digit of all the N numbers is divisible by 10.

Example:

Input:  n = 5, a = [85,25,65,21,84]
Output: No

Approach

C++

#include <bits/stdc++.h>
using namespace std;

bool divisibility(int nint a[])
{
    if (a[n - 1] % 10 == 0)
        return true;
    return false;
}
int main()
{
    int n = 5;
    int a[n] = {8525652184};

    if (divisibility(na))
        cout << "Yes\n";
    else
        cout << "No\n";
}


No comments:

Post a Comment