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

Procedure of Arriving at Kaprekar's Constant Using C Programme

The document describes a C program that calculates Kaprekar's constant by iterating through four-digit numbers. The program takes a four-digit input number, separates its digits into an array, calculates the ascending and descending order numbers, takes the difference, and iterates until reaching 6174. The program is useful for efficiently arriving at Kaprekar's constant from any four-digit starting number and studying properties of the iterative process.

Uploaded by

036-AJAY MIDDELA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views2 pages

Procedure of Arriving at Kaprekar's Constant Using C Programme

The document describes a C program that calculates Kaprekar's constant by iterating through four-digit numbers. The program takes a four-digit input number, separates its digits into an array, calculates the ascending and descending order numbers, takes the difference, and iterates until reaching 6174. The program is useful for efficiently arriving at Kaprekar's constant from any four-digit starting number and studying properties of the iterative process.

Uploaded by

036-AJAY MIDDELA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

International Journal of Electrical Electronics & Computer Science Engineering

Volume 2, Issue 3 (June, 2015) | E-ISSN : 2348-2273 | P-ISSN : 2454-1222


Available Online at www.ijeecse.com

Procedure of Arriving at Kaprekar’s Constant using C Programme


Suresh Shivarudrappa Hiremath1, Shripad Gurunathrao Kulkarni 2
1
Assistant Professor, General Engineering &Sciences, Brahmdevdada Mane Institute of Technology, Solapur, India
2
Assistant Professor, Computer Science &Engineering, Brahmdevdada Mane Institute of Technology, Solapur, India
1
[email protected], [email protected]

Abstract: In this paper we have given computer programme to #include<math.h>


obtain Kaprekar’s constant using C. Using which one can start #include<dos.h>
with any number from set of all positive four digit numbers
where none of its any three digits are equal as input and will void main()
get directly a Kaprekar’s Constant. {
Keywords: Kaprekar’s constant, C programme, Fixed point, int n;
Iterative function, Four digit numbers. clrscr();
printf("\n\nEnter any four digit no.\n");
I. INTRODUCTION
scanf("%d",&n);
D R Kaprekar invented different number properties printf("\n\nfound %d",fixpoint(n));
throughout his life. He was not well known, however
getch();
despite many of his papers being reviewed in
Mathematical Reviews. International fame came in1975 }
when Martin Gardener wrote about Kaprekar and his int fixpoint(int no)
numbers in his ‘Mathematical Games’ column in the {
March issue of Scientific American. The fascination for int d[4],a,b,diff,ono;
numbers which Kaprekar had as a child continued static int c=0;
throughout his life. He realized that he was addicted to
ono=no;
number theory[6].
d[3]=no%10;
Kaprekar’s name today is well known and many //printf("\n%d",d[3]);
mathematicians have found themselves intrigued by the
//delay(1000);
ideas about numbers which Kaprekar found so addictive.
The best known of Kaprekar’s results is the following no=no/10;
which relates to the number 6174, today called Kaprekar’s d[2]=no%10;
Constant. One starts with any four digit number whose //printf("\n%d",d[2]);
any three digits are not equal. Rearrange the digits to form //delay(1000);
the largest and smallest numbers with these digits and no=no/10;
subtract the smaller from the larger. Continue this process
d[1]=no%10;
with the resulting number. Finally we obtain the four digit
number 6174 where this process terminates. The process //printf("\n%d",d[1]);
of obtaining Kaprekar’s constant by using iterative //delay(1000);
method is explained in [1] no=no/10;
Knowing this procedure it seems somewhat difficult to d[0]=no%10;
obtain Kaprekar’s constant from any four digit number //printf("\n%d\n",d[0]);
manually. Also if we want to know about the number of no=no/10;
iterations that required to obtain Kaprekar’s constant. a=as(d);
Then it becomes somewhat tedious job. So in order to
//delay(1000);
study different properties in this regard we think of the
following systematic procedure that is C programme for getch();
Kaprekar’s constant. printf("your no. %d is in assending order
is=%d\n",ono,a);
II. C P ROGRAMME FOR KAPREKAR’S b=ds(d);
CONSTANT //delay(1000);
#include<stdio.h> //getch();
#include<conio.h>

37
International Journal of Electrical Electronics & Computer Science Engineering
Volume 2, Issue 3 (June, 2015) | E-ISSN : 2348-2273 | P-ISSN : 2454-1222
Available Online at www.ijeecse.com

printf("your no. %d is in dessending order x[j]=temp;


is=%d\n",ono,b); }
// printf("%d\n",b); }
diff=abs(a-b); }
//getch(); sum=x[0]*1000+x[1]*100+x[2]*10+x[3];
printf("the diff betn %d and %d is= %d",a,b,diff); return(sum);
c++; }
//getch();
In [1] Hiremath and Kakde has given the detail procedure
printf("\nrequired iterations are=%d\n",c); for obtaining Kaprekar’s constant manually. While
//printf("%d",diff); generating above programme we have used the following
if(ono==diff) definition of Kaprekar’s constant.
return(diff);
III. DEFINITION
printf("In iteration %d i didn't get ur no. so i am going to
find one more time\n",c); Let X be the set of all positive four digit numbers. Define
fixpoint(diff); f : X  X such that , then there exists a
}  
unique element x  X such that f x  x . This unique
int as(int x[4]) four digit number is called Kaprekar’s Constant and it is a
{ fixed point of iterative function f : X  X and is given
int i,j,temp,sum; by 6174.
for(i=0;i<=2;i++) Where x is a positive four digit number. denotes the
{ number obtained from x by rearranging its digits in
for(j=i+1;j<=3;j++) descending order and denotes the number obtained from
{ x by rearranging its digits in ascending order.
if(x[i]>x[j]) IV. SUMMARY
{
The C programme given in this paper is useful to arrive at
temp=x[i];
Kaprekar’s constant starting with any four digit number
x[i]=x[j]; within few seconds and is also useful to study different
x[j]=temp; properties of such four digit numbers.
}
V. REFERENCES
}
} [1] Kaprekar’s Constant as a Fixed Point of Iterative
sum=x[0]*1000+x[1]*100+x[2]*10+x[3]; Function by Hiremath S S and Kakde R V IOSR
Journal of Mathematics (IOSR-JM) Volume 9, Issue
return(sum);
3 (Nov.– Dec. 2013), PP 06-07.
}
int ds(int x[4]) [2] Investigations into the Kaprekar Process by Robert
{ W. Ellis and Jason R. Lewis.
int i,j,temp,sum; [3] An Interesting Property of the Number 6174, Scripta
for(i=0;i<=2;i++) Math, 21(1955)304 by D R Kaprekar.
{ [4] The Determination of Kaprekar Convergence and
for(j=i+1;j<=3;j++) Loop Convergence of All Three-Digit numbers.
American Monthly,95(1988,105-112) by Klaus E.
Eldridge and Seok Sangong.
{
if(x[i]<x[j]) [5] The Kaprekar Routine and Other Digit Games for
{ Undergraduate Exploration by K Peterson and H
temp=x[i]; Pulapaka.
x[i]=x[j]; [6] Mac Tutor History of Mathematics, Article by J J
O’Connor and E F Robertson.
38

You might also like