2 points

Code to count numbers on your fingers


dashboard

Thu Dec 26 2019 15:18:45 GMT+0000 (UTC)

Posted by @vasquezthefez #php #interesting #interviewquestions #logic

<?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)); 
 
?> 
content_copy

Count up to any number 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 moving backwards, six comes on the ring finger and so on.

https://www.geeksforgeeks.org/program-count-numbers-fingers/

>> Browse more code snippets

@divisionjava - Thu Dec 26 2019 15:34:17 GMT+0000 (UTC)
// 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)); 
} 
} 

For those interested in Java.. pulled code from the same link.

more_vert