WAP to input a two digit number and print the square of both of its digits. Eg : input -> 47 Output -> 16 (i.e. 4*4=16) 49 (i.e. 7*7=49)
Answers
Answered by
2
As no programming language is mentioned, I am writing this in Java.
import java.util.Scanner;
public class Brainly{
public static void main(String s[]){
int number, f,l;
Scanner sc=new Scanner(System.in);
System.out.print("Enter a two digit integer number: ");
number=sc.nextInt();
sc.close();
f=number/10;
l=number%10;
System.out.printf("Square of first digit = %d x %d = %d\n",f,f,f * f);
System.out.printf("Square of last digit = %d x %d = %d",l,l,l * l);
}
}
- Line 1: Scanner class is taken as input.
- Line 2: Class declaration.
- Line 3: Start of main() method.
- Line 4: Three variables are declared which stores the number and the first and last digit of it.
- Line 5: Object of scanner class is created.
- Line 6: Ask the user to enter the number.
- Line 7: Number is taken as input.
- Line 8: Scanner closed.
- Line 9-10: First and last digit calculated.
- Line 11-12: Squares of the digits are displayed.
- Line 13: End of main().
- Line 14: End of class.
See attachment for output.
Attachments:
Similar questions