# Check if the number formed by the last digits of N numbers is divisible by 10 or not

Given an array **arr[]** of size **N** consisting of non-zero positive integers. The task is to determine whether the number that is formed by selecting the last digits of all the numbers is divisible by 10 or not. If the number is divisible by 10, then print Yes otherwise print No.

**Examples:**

Input:arr[] = {12, 65, 46, 37, 99}

Output:No

25679 is not divisible by 10.

Input:arr[] = {24, 37, 46, 50}

Output:Yes

4760 is divisible by 10.

**Approach:** In order for an integer to be divisible by 10, it must be ending with a 0. So, the last element of the array will decide whether the number formed will be divisible by 10 or not. If the last digit of the last element is 0 then print Yes otherwise print No.

Below is the implementation of the above approach:

## C++

`// C++ implementation of the approach ` `#include <iostream> ` `using` `namespace` `std; ` ` ` `// Function that returns true if the ` `// number formed by the last digits of ` `// all the elements is divisible by 10 ` `bool` `isDivisible(` `int` `arr[], ` `int` `n) ` `{ ` ` ` `// Last digit of the last element ` ` ` `int` `lastDigit = arr[n - 1] % 10; ` ` ` ` ` `// Number formed will be divisible by 10 ` ` ` `if` `(lastDigit == 0) ` ` ` `return` `true` `; ` ` ` ` ` `return` `false` `; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `arr[] = { 12, 65, 46, 37, 99 }; ` ` ` `int` `n = ` `sizeof` `(arr) / ` `sizeof` `(arr[0]); ` ` ` ` ` `if` `(isDivisible(arr, n)) ` ` ` `cout << ` `"Yes"` `; ` ` ` `else` ` ` `cout << ` `"No"` `; ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the approach ` `import` `java.util.*; ` ` ` `class` `GFG ` `{ ` ` ` `// Function that returns true if the ` `// number formed by the last digits of ` `// all the elements is divisible by 10 ` `static` `boolean` `isDivisible(` `int` `arr[], ` `int` `n) ` `{ ` ` ` `// Last digit of the last element ` ` ` `int` `lastDigit = arr[n - ` `1` `] % ` `10` `; ` ` ` ` ` `// Number formed will be divisible by 10 ` ` ` `if` `(lastDigit == ` `0` `) ` ` ` `return` `true` `; ` ` ` ` ` `return` `false` `; ` `} ` ` ` `// Driver code ` `static` `public` `void` `main ( String []arg) ` `{ ` ` ` `int` `arr[] = { ` `12` `, ` `65` `, ` `46` `, ` `37` `, ` `99` `}; ` ` ` `int` `n = arr.length; ` ` ` ` ` `if` `(isDivisible(arr, n)) ` ` ` `System.out.println(` `"Yes"` `); ` ` ` `else` ` ` `System.out.println(` `"No"` `); ` `} ` `} ` ` ` `// This code is contributed by Rajput-Ji ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of the approach ` ` ` `# Function that returns true if the ` `# number formed by the last digits of ` `# all the elements is divisible by 10 ` `def` `isDivisible(arr, n) : ` ` ` ` ` `# Last digit of the last element ` ` ` `lastDigit ` `=` `arr[n ` `-` `1` `] ` `%` `10` `; ` ` ` ` ` `# Number formed will be divisible by 10 ` ` ` `if` `(lastDigit ` `=` `=` `0` `) : ` ` ` `return` `True` `; ` ` ` ` ` `return` `False` `; ` ` ` `# Driver code ` `if` `__name__ ` `=` `=` `"__main__"` `: ` ` ` ` ` `arr ` `=` `[ ` `12` `, ` `65` `, ` `46` `, ` `37` `, ` `99` `]; ` ` ` `n ` `=` `len` `(arr); ` ` ` ` ` `if` `(isDivisible(arr, n)) : ` ` ` `print` `(` `"Yes"` `); ` ` ` `else` `: ` ` ` `print` `(` `"No"` `); ` ` ` `# This code is contributed by AnkitRai01 ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of the approach ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// Function that returns true if the ` `// number formed by the last digits of ` `// all the elements is divisible by 10 ` `static` `bool` `isDivisible(` `int` `[]arr, ` `int` `n) ` `{ ` ` ` `// Last digit of the last element ` ` ` `int` `lastDigit = arr[n - 1] % 10; ` ` ` ` ` `// Number formed will be divisible by 10 ` ` ` `if` `(lastDigit == 0) ` ` ` `return` `true` `; ` ` ` ` ` `return` `false` `; ` `} ` ` ` `// Driver code ` `static` `public` `void` `Main(String []arg) ` `{ ` ` ` `int` `[]arr = { 12, 65, 46, 37, 99 }; ` ` ` `int` `n = arr.Length; ` ` ` ` ` `if` `(isDivisible(arr, n)) ` ` ` `Console.WriteLine(` `"Yes"` `); ` ` ` `else` ` ` `Console.WriteLine(` `"No"` `); ` `} ` `} ` ` ` `// This code is contributed by Rajput-Ji ` |

*chevron_right*

*filter_none*

**Output:**

No

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.

## Recommended Posts:

- N digit numbers divisible by 5 formed from the M digits
- Sum of all N digit palindromic numbers divisible by 9 formed using digits 1 to 9
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Check if the large number formed is divisible by 41 or not
- Check if the sum of digits of number is divisible by all of its digits
- Program to check if a number is divisible by sum of its digits
- Check if N is divisible by a number which is composed of the digits from the set {A, B}
- Program to check if a number is divisible by any of its digits
- Check whether sum of digits at odd places of a number is divisible by K
- Given a large number, check if a subsequence of digits is divisible by 8
- Check whether product of digits at even places of a number is divisible by K
- Find N numbers such that a number and its reverse are divisible by sum of its digits
- Check if number formed by joining two Numbers is Perfect Cube
- Check if two numbers have same number of digits
- Check if B can be formed by permuting the binary digits of A
- Count numbers formed by given two digit with sum having given digits
- Minimum sum of two numbers formed from digits of an array
- Find the count of numbers that can be formed using digits 3, 4 only and having length at max N.
- Number formed by deleting digits such that sum of the digits becomes even and the number odd

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.