From 84977cb9f4416841eae674058427530cd1d1799c Mon Sep 17 00:00:00 2001 From: M Sajid Mansoori Date: Wed, 30 Sep 2020 22:38:22 +0530 Subject: [PATCH 1/2] Added program for kaprekar number --- C/program-47/kaprekar_number.c | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 C/program-47/kaprekar_number.c diff --git a/C/program-47/kaprekar_number.c b/C/program-47/kaprekar_number.c new file mode 100644 index 00000000..37f77482 --- /dev/null +++ b/C/program-47/kaprekar_number.c @@ -0,0 +1,42 @@ +/* A kaprekar number is a number in base 10 whose square can be split such that the the sum of those numbers +add up to the original number for eg : (45)^2 = 2025 => 20+25=45 */ + + # include + # include + # include + # include + bool iskaprekarnum(int n) + { + if (n == 1) // If the number passed is 1 then it is also considered to be a kaprekar number + return true; + int square_number = n * n; // Finding the square + int count_digits = 0; //This will be the counter variable for the number of digits in the number + while (square_number != 0) + { + count_digits++; + square_number /= 10; + } + square_number = n*n; // Recalculating square as it was changed in the above while loop + for (int r_digits=1; r_digits Date: Wed, 30 Sep 2020 22:39:10 +0530 Subject: [PATCH 2/2] Added program for kaprekar number --- C/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/C/README.md b/C/README.md index 9251eeaa..a80634a0 100644 --- a/C/README.md +++ b/C/README.md @@ -48,6 +48,7 @@ | Program-44 | Program for implementation of the approach | | Program-45 | Program to illustrate the above given pattern of numbers. | | Program-46 | Program to convert binary number to decimal | +| Program-47 | Program to print kaprekar number in a given range |