write a program to check weather it is a karoker number
mn121:
What is a karoker number
Answers
Answered by
1
import java.util.*;
public class kaprekar
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int n,i,sq,d=0,r,q,c=0;
System.out.println("Enter a number = ");
n=in.nextInt();
sq=n*n;
for(i=sq;i!=0;i=i/10)
{
d++;
}
for(i=1;i<d;i++)
{
r=sq%(int)(Math.pow(10,i));
q=sq/(int)(Math.pow(10,i));
if(r==0||q==0)
continue;
if(n==(r+q))
c++;
}
if(c!=0)
System.out.println(n+" is a kaprekar number");
else
System.out.println(n+"is not a kaprekar number");
}
}
Similar questions