Patrick started to play the card game - V. In this game, Patrick has to pick one card from the shuffled cards. If the card number is a Kaprekar number, then he wins the game. Patrick is unaware of Kaprekar number. Patrick decided to ask the manager about this number.
The manager explains to him that 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 & 8+1=9.
297 is a Kaprekar number since 2972 = 88209 & 88+209 = 297.

Write a program to help Patrick to find whether a card number he picked is a Kaprekar number or not.

Input Format:
Input consists of a single integer.

Output Format:
Refer sample output for details.

Sample Input and Output1: 
Enter the card number picked up by Patrick:

9 is a Kaprekar Number

Sample Input and Output 2:
Enter the card number picked up by Patrick:
101
101 is not a Kaprekar Number


Program Code:

# include <stdio.h>
# include <stdbool.h>
# include <math.h>
bool chkkaprekar(int n)
{
int r_digits;
if (n == 1)
 return true;
    int sqr_n = n * n;
    int ctr_digits = 0;
    while (sqr_n)
    {
        ctr_digits++;
        sqr_n /= 10;
    }
    sqr_n = n*n; 
    for (r_digits=1; r_digits<ctr_digits; r_digits++)
    {
         int eq_parts = pow(10, r_digits);

         if (eq_parts == n)
            continue;
         int sum = sqr_n/eq_parts + sqr_n % eq_parts;
         if (sum == n)
           return true;
}
return false;
}
int main()
{
int kpno;
  printf("Enter the card number picked up by Patrick:\n");
  scanf("%d",&kpno);
if (chkkaprekar(kpno)==true)
{
printf("%d is a Kaprekar Number",kpno);
}
else
{
printf("%d is not a Kaprekar Number",kpno);
}
 return 0;

}
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

8 comments:

  1. I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own Blog Engine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it. solitaire card games free

    ReplyDelete
  2. Wow, What a Excellent post. I really found this to much informatics. It is what i was searching for.I would like to suggest you that please keep sharing such type of info.Thanks wordfeud generator

    ReplyDelete
  3. I expected much more from your news. I found it on Bing and hoped it will be more informative see here

    ReplyDelete
  4. I love the way you write and share your niche! Very interesting and different! Keep it coming! Satta king up

    ReplyDelete
  5. Excellent and very exciting site. Love to watch. Keep Rocking. https://redditnhlstreaming.live/

    ReplyDelete
  6. This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post. https://nhlstreaminglinks.website/

    ReplyDelete
  7. Nice to read your article! I am looking forward to sharing your adventures and experiences. https://redditufcstream.live/

    ReplyDelete