Count the given numbers on your fingers and find the correct finger on which the number ends.

- The first number starts from the thumb, second on the index finger, third on the middle finger, fourth on the ring finger and fifth on the little finger.
- Again six comes on the ring finger and so on.

**Examples:**

Input : 17 Output :1 Input :27 Output :3

## C++

`// CPP Program to Count numbers on fingers ` `#include <iostream> ` `using` `namespace` `std; ` ` ` `int` `count_num_finger(` `int` `n) ` `{ ` ` ` `int` `r = n % 8; ` ` ` `if` `(r == 1) ` ` ` `return` `r; ` ` ` `if` `(r == 5) ` ` ` `return` `r; ` ` ` `if` `(r == 0 || r == 2) ` ` ` `return` `2; ` ` ` `if` `(r == 3 || r == 7) ` ` ` `return` `3; ` ` ` `if` `(r == 4 || r == 6) ` ` ` `return` `4; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `n; ` ` ` `n = 30; ` ` ` `cout << count_num_finger(n); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java Program to Count numbers on fingers ` `class` `GFG ` `{ ` `static` `int` `count_num_finger(` `int` `n) ` `{ ` ` ` `int` `r = n % ` `8` `; ` ` ` `if` `(r == ` `1` `) ` ` ` `return` `r; ` ` ` `if` `(r == ` `5` `) ` ` ` `return` `r; ` ` ` `if` `(r == ` `0` `|| r == ` `2` `) ` ` ` `return` `2` `; ` ` ` `if` `(r == ` `3` `|| r == ` `7` `) ` ` ` `return` `3` `; ` ` ` `if` `(r == ` `4` `|| r == ` `6` `) ` ` ` `return` `4` `; ` ` ` `return` `n; ` `} ` ` ` `// Driver Code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` `int` `n; ` ` ` `n = ` `30` `; ` ` ` `System.out.println(count_num_finger(n)); ` `} ` `} ` ` ` `// This code is contributed ` `// by Mukul Singh ` |

*chevron_right*

*filter_none*

## Python3

`def` `count_num_finger( n ): ` ` ` `r ` `=` `n ` `%` `8` ` ` `if` `r ` `=` `=` `1` `: ` ` ` `return` `r ` ` ` `if` `r ` `=` `=` `5` `: ` ` ` `return` `r ` ` ` `if` `r ` `=` `=` `0` `or` `r ` `=` `=` `2` `: ` ` ` `return` `2` ` ` `if` `r ` `=` `=` `3` `or` `r ` `=` `=` `7` `: ` ` ` `return` `3` ` ` `if` `r ` `=` `=` `4` `or` `r ` `=` `=` `6` `: ` ` ` `return` `4` ` ` `# Driver Code ` `n ` `=` `30` `print` `(count_num_finger(n)) ` ` ` `# This code is contributed by "Sharad_Bhardwaj". ` |

*chevron_right*

*filter_none*

## C#

`// C# Program to Count numbers on fingers ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `static` `int` `count_num_finger(` `int` `n) ` `{ ` ` ` `int` `r = n % 8; ` ` ` `if` `(r == 1) ` ` ` `return` `r; ` ` ` `if` `(r == 5) ` ` ` `return` `r; ` ` ` `if` `(r == 0 || r == 2) ` ` ` `return` `2; ` ` ` `if` `(r == 3 || r == 7) ` ` ` `return` `3; ` ` ` `if` `(r == 4 || r == 6) ` ` ` `return` `4; ` ` ` `return` `n; ` `} ` ` ` `// Driver Code ` `public` `static` `void` `Main(String[] args) ` `{ ` ` ` `int` `n; ` ` ` `n = 30; ` ` ` `Console.WriteLine(count_num_finger(n)); ` `} ` `} ` ` ` `// This code is contributed by Princi Singh ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `function` `count_num_finger( ` `$n` `) ` `{ ` ` ` `$r` `= ` `$n` `% 8; ` ` ` `if` `(` `$r` `== 1) ` ` ` `return` `$r` `; ` ` ` `if` `(` `$r` `== 5) ` ` ` `return` `$r` `; ` ` ` `if` `(` `$r` `== 0 ` `or` `$r` `== 2) ` ` ` `return` `2; ` ` ` `if` `(` `$r` `== 3 ` `or` `$r` `== 7) ` ` ` `return` `3; ` ` ` `if` `(` `$r` `== 4 ` `or` `$r` `== 6) ` ` ` `return` `4; ` `} ` ` ` `// Driver Code ` `$n` `= 30; ` `echo` `(count_num_finger(` `$n` `)); ` ` ` `// This code is contributed ` `// by Aman Ojha ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

4

Asked in Paytm Campus Placement August 2017

This article is contributed by **Dinesh Malav**. 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

## Recommended Posts:

- Maximize count of equal numbers in Array of numbers upto N by replacing pairs with their sum
- Check if count of Alphabets and count of Numbers are equal in the given String
- Python program to count Even and Odd numbers in a List
- Python program to count positive and negative numbers in a list
- C program to count Positive and Negative numbers in an Array
- Maximum sum of distinct numbers such that LCM of these numbers is N
- Find ratio of zeroes, positive numbers and negative numbers in the Array
- Count numbers that don't contain 3
- Count numbers with unit digit k in given range
- Count Odd and Even numbers in a range from L to R
- Count of Octal numbers upto N digits
- Count of numbers upto M with GCD equals to K when paired with M
- Count of numbers with all digits same in a given range
- Count of ways to write N as a sum of three numbers
- Count of decreasing pairs formed from numbers 1 to N
- Count of numbers in Array ending with digits of number N
- Count of Missing Numbers in a sorted array
- Count all N digit numbers whose digits are multiple of X
- Program to print a pattern of numbers
- C Program to Swap two Numbers