find first and last digit of a number

find first and last digit of a number without using loop

Welcome back to shortlearner.com, in this post we will see how to write a program to find first and last digit of a number without using any type of loop.

so in the below program we are declaring a php variable $n which will takes the number.
here we are defining 2 php functions which will returns the first and last digit of our $n number.

Advertisement
find first and last digit of a number

the first function is firstNumber which will accept $n as a parameter than we use log10() function.

now we will take an short overview of log10() function. basically log10() is a mathematical function which is defined in math.h header file and it returns log base 10 value of the passed paramater.

Also Read
How to Install PHP on CentOS.
How to Send Attachment on mail using PHP.

PHP Login Script With Remember me.
Unable to create a directory a wordpress error

How to integrate Razorpay Payment Gateway using PHP.
Change password using javascript, php and mysqli.
Password and Confirm Password Validation Using JavaScript

Check Email is Already Registered in Database using Ajax and JavaScript.
How to hide extension of html and php file.?

than we use pow() function. so basically pow() is a predefined function which will return the first number to the power of second number. in other words we can say that it compute power of a certain number. this function takes 2 parameter which are the base and exponent and returns the desired answer.

after using pow() function we will get first digit of our $n number. now we will declare our second function lastNumer which will help us to find out the last digit of $n number.

If these article helps you please share it with your developers buddy.
and if you are a web designer and looking for amazing snippets thank click on the below button.

Amazing Snippets

Keep Learning, Keep Coding

Tags: No tags

Comments are closed.