Search
 
SCRIPT & CODE EXAMPLE
 

CPP

first and last digit of a number in java

public class Main
{  
    public static void main(String args[])
    {  
        int number = 502356997;
        int firstDigit = 0;
        int lastDigit = 0;
 
        lastDigit = number%10;
        System.out.println("Last digit: "+lastDigit);
 
        while(number!=0) {
            firstDigit = number%10;
            number /= 10;
        }
        System.out.println("First digit: "+firstDigit);
    }
}
Comment

Find first and last digit of int

#include <iostream>
using namespace std;

int main()
{
    int number;
    cout << "Enter a number : " << endl;
    cin >> number;

    cout << "Last digit is : " << number % 10 << endl;

    while(number >= 10){
        number = number/10;
    }

    cout<< "First digit is : "<< number << endl;
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ copy string 
Cpp :: qt how to make a file browser 
Cpp :: Arduino Counting 
Cpp :: passare un array a una funzione 
Cpp :: frequency of characters in a string in c++ 
Cpp :: how to define range of numbers inside a if condition in c++ 
Cpp :: convert c++ to mips assembly code online 
Cpp :: 2927260.eps 2927262.jpg 2927263.ai License free.txt License premium.txt 
Cpp :: friend class c++ 
C :: run time in c 
C :: matplotlib legend remove box 
C :: boolean in c 
C :: write in file in c 
C :: div en langage c 
C :: bubble sort a linked list in c 
C :: c boolean 
C :: remove from string c 
C :: printf c float 
C :: dynamically create matrix c 
C :: c bit access union 
C :: how to print the first character of a string in c 
C :: malloc in c 
C :: c syntax 
C :: c printing char pointer 
C :: c in array 
C :: epoch time in c 
C :: how i send custom data in model field rest_framework serializer 
C :: latex remove page number from footer 
C :: how to get the lowest number on a array in c 
C :: c calculate median 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =