Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <math.h>
  4. #define TRUE 1
  5. #define FALSE 2
  6.  
  7. int isKaprekar(long int num)
  8. {
  9.  
  10. if (num == 1)
  11. return TRUE;
  12. int squar_num = num * num;
  13. int countDigits = 0;
  14. while (squar_num > 0)
  15. {
  16. squar_num = squar_num / 10;
  17. countDigits = countDigits + 1;
  18. }
  19. squar_num = num * num;
  20. for (int i = 1; i < countDigits; i++)
  21. {
  22. int half = pow(10, i);
  23. if (half == num)
  24. continue;
  25. int sum = (squar_num / half) + (squar_num % half);
  26. if (sum == num) {
  27. printf("this is Karpanker number\n");
  28.  
  29. }
  30.  
  31. }
  32.  
  33. printf("this is not Karpanker number\n");
  34.  
  35.  
  36.  
  37. }
  38.  
  39.  
  40.  
  41. int getMiddleMult(long int num)
  42. {
  43. int countDigits = 0;
  44. while ( num > 0) {
  45. num = num / 10;
  46. countDigits = countDigits+1;
  47. }
  48. printf("the amount of digits are %d\n", countDigits);
  49.  
  50. int sum = 10;
  51. if (countDigits % 2 == 0){
  52. countDigits = countDigits / 2;
  53. for (int i = 0; i < countDigits; i++)
  54. {
  55. sum = sum*10;
  56. }
  57. printf("the number is even, and 10 power is %ld\n", sum);
  58. }
  59. else if (countDigits = (countDigits / 2)+1)
  60. {
  61. for (int i = 0; i < countDigits; i++)
  62. {
  63. sum = sum * 10;
  64. }
  65. printf("the number is odd, and 10 power is %ld\n", sum);
  66.  
  67. }
  68. }
  69.  
  70.  
  71. void main()
  72. {
  73. long int number;
  74. printf("Enter a number: ");
  75. scanf("%ld", &number);
  76. isKaprekar(number);
  77. getMiddleMult(number);
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement