Horje
first and last digit of a number in c++ Code Example
first and last digit of a number in c++
// Program to find first and last
// digits of a number
#include <bits/stdc++.h>
using namespace std;
 
// Find the first digit
int firstDigit(int n)
{
    // Find total number of digits - 1
    int digits = (int)log10(n);
 
    // Find first digit
    n = (int)(n / pow(10, digits));
 
    // Return first digit
    return n;
}
 
// Find the last digit
int lastDigit(int n)
{
    // return the last digit
    return (n % 10);
}
 
// Driver program
int main()
{
    int n = 98562;
    cout << firstDigit(n) << " "
         << lastDigit(n) << endl;
    return 0;
}




Cpp

Related
c++ insertion in astack Code Example c++ insertion in astack Code Example
macro c++ Code Example macro c++ Code Example
10^18 data type in c++ Code Example 10^18 data type in c++ Code Example
unpack tuple c++ Code Example unpack tuple c++ Code Example
online c++ compiler Code Example online c++ compiler Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7