Computer Science, asked by shaniyaalam2000, 1 year ago

WAP to input a number and check the number is karpakar number or not.A karpakar number is a number whose square if splitted in two parts and added the sum is itself the number for example 45^2=2025 and 20+25=45

Answers

Answered by charlie1505
0

Answer:

The Penguin Coders

This Website Provides You With Quality Articles On Programming Languages And How To Tutorials In Windows, Linux And Android

Home

Privacy Policy

Contact Us

About Us

Code Contest

Tech Forum

Windows

Linux

Check whether a number is Kaprekar number or not.

This program checks whether a number is Kaprekar number or not.

A number is said to be Kaprekar number if its sum of digits in its square is the number itself.

Example- 9^2 is 81 and 8+1 is 9.So it is a Kaprekar number.

import java.util.*;

public class KaprekarNumbers

{

public static void main(String args[])

{

Scanner ob=new Scanner(System.in);

System.out.println("Enter number");

int n=ob.nextInt();

int N=n*n;

int tn=n;int c=0;

while(tn!=0)

{

tn=tn/10;c++;

}

int q=(int)(N/Math.pow(10,c));

int r=(int)(N%Math.pow(10,c));

if(q+r==n)

System.out.println("Kaprekar number");

else

System.out.println("Non Kaprekar number");

}

}

Similar questions