Computer Science, asked by tabashmidutta, 3 days ago

WAP to input a five digit number and print product of its first and second last digits​

Answers

Answered by koushikreddy2004
0

Well you need to specify the program language,

Alright imma give the program in 6 languages

C++

#include <bits/stdc++.h>

using namespace std;

// Find the first digit

int firstDigit(int n)

{

// Remove last digit from number

// till only one digit is left

while (n >= 10)

 n /= 10;

 

// return the 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;

}

__________

Java

__________

import java.util.*;

import java.lang.*;

public class GfG{

 

// Find the first digit

public static int firstDigit(int n)

{

 // Remove last digit from number

 // till only one digit is left

 while (n >= 10)

  n /= 10;

 

 // return the first digit

 return n;

}

// Find the last digit

public static int lastDigit(int n)

{

 // return the last digit

 return (n % 10);

}

 

// driver function

public static void main(String argc[])

{

 int n = 98562;

 System.out.println(firstDigit(n) + " "

 + lastDigit(n));

}

}

Similar questions