WAP to to input a number and check if it is a KAPRYKAR number or not.
Example:
Example:
(999)2=998001
99800+1=99801
9980+1=9981
998+1=999
So its a KAPRYKAR NUMBER.
#include <stdio.h>
#include <conio.h>
void main()
{
int kp=0,d1,d2,sq,n,div=10;
printf("Enter the number");
scanf("%d",&n);
sq=n*n;
while(div>0)
{
d1=sq%div;
d2=sq/div;
if(d1+d2==n)
{
kp=1;
}
if(d2<=9)
{
break;
}
div=div*10;
}
if(kp==1)
printf("KAPRYKAR NUMBER");
else
printf("NOT KAPRYKAR NUMBER");
}
#include <conio.h>
void main()
{
int kp=0,d1,d2,sq,n,div=10;
printf("Enter the number");
scanf("%d",&n);
sq=n*n;
while(div>0)
{
d1=sq%div;
d2=sq/div;
if(d1+d2==n)
{
kp=1;
}
if(d2<=9)
{
break;
}
div=div*10;
}
if(kp==1)
printf("KAPRYKAR NUMBER");
else
printf("NOT KAPRYKAR NUMBER");
}
No comments:
Post a Comment