0% found this document useful (0 votes)
190 views2 pages

KAPREKAR

This C program identifies Kaprekar numbers less than 1000. It takes an input number, calculates its square, separates the squared number into left and right digits, sums them, and checks if the sum equals the original number. If so, the number is printed as a Kaprekar number. The program includes functions to determine the number of digits and perform the Kaprekar checking logic.

Uploaded by

Swapnilghorpade
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
190 views2 pages

KAPREKAR

This C program identifies Kaprekar numbers less than 1000. It takes an input number, calculates its square, separates the squared number into left and right digits, sums them, and checks if the sum equals the original number. If so, the number is printed as a Kaprekar number. The program includes functions to determine the number of digits and perform the Kaprekar checking logic.

Uploaded by

Swapnilghorpade
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

//http://en.wikipedia.org/wiki/D._R.

_Kaprekar
/*Kaprekar Numbers
Consider an n-digit number k. Square it and add the right n digits to the left n
or n-1 digits.
If the resultant sum is k, then k is called a Kaprekar number.
For example, 9 is a Kaprekar number since 92 = 81 and 8 + 1 = 9
and 297 is a Kaprekar number since 2972 = 88209 and 88 + 209 = 297.
*/
//task is to write a function that identifies Kaprekar numbers
//and to determine the Kaprekar numbers less than a thousand.
#include <stdio.h>
#include<math.h>
int nodigits( int p);
void kapre(long int num,long int d_num,long int sqr);
int main()
{
long int sqn,nD;
int i;
clrscr();
for(i=1;i<1000;i++)
{
nD=nodigits(i);
sqn=pow(i,2);
kapre(i,nD,sqn);
}
getch();
return 0;
}
int nodigits(int p)
{
int j=0;
while(p!=0)
{ p=p/10;
j++;
}
return j;
}
void kapre( long int num, long int d_num, long int sqr)
{
long int sum1=0,revsum=0;
int i;
for(i=0;i<d_num;i++)
{sum1=(sum1*10)+ sqr%10;
sqr/=10;
}
while(sum1!=0)
{
revsum=(revsum*10)+(sum1%10);
sum1/=10;
}
if((revsum+sqr)==num)
{
printf("\n %ld is A KARAMKAR NUMBER",num);
}
}

You might also like