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 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/