Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <math.h>
- #define TRUE 1
- #define FALSE 2
- int isKaprekar(long int num)
- {
- if (num == 1)
- return TRUE;
- int squar_num = num * num;
- int countDigits = 0;
- while (squar_num > 0)
- {
- squar_num = squar_num / 10;
- countDigits = countDigits + 1;
- }
- squar_num = num * num;
- for (int i = 1; i < countDigits; i++)
- {
- int half = pow(10, i);
- if (half == num)
- continue;
- int sum = (squar_num / half) + (squar_num % half);
- if (sum == num) {
- printf("this is Karpanker number\n");
- }
- }
- printf("this is not Karpanker number\n");
- }
- int getMiddleMult(long int num)
- {
- int countDigits = 0;
- while ( num > 0) {
- num = num / 10;
- countDigits = countDigits+1;
- }
- printf("the amount of digits are %d\n", countDigits);
- int sum = 10;
- if (countDigits % 2 == 0){
- countDigits = countDigits / 2;
- for (int i = 0; i < countDigits; i++)
- {
- sum = sum*10;
- }
- printf("the number is even, and 10 power is %ld\n", sum);
- }
- else if (countDigits = (countDigits / 2)+1)
- {
- for (int i = 0; i < countDigits; i++)
- {
- sum = sum * 10;
- }
- printf("the number is odd, and 10 power is %ld\n", sum);
- }
- }
- void main()
- {
- long int number;
- printf("Enter a number: ");
- scanf("%ld", &number);
- isKaprekar(number);
- getMiddleMult(number);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement