-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodifiedkarpkarnumber.c
More file actions
65 lines (54 loc) · 1.13 KB
/
modifiedkarpkarnumber.c
File metadata and controls
65 lines (54 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// https://www.hackerrank.com/challenges/kaprekar-numbers/problem
#include <stdio.h>
#include <math.h>
int main(void)
{
unsigned int long long lower, upper;
scanf("%llu%llu", &lower, &upper);
unsigned int long long start = lower;
int haveNum = 0;
while (start <= upper)
{
unsigned int long long temp = start;
int count = 0;
while (temp != 0)
{
count++;
temp = temp / 10;
}
unsigned long long int square = start * start;
unsigned int long long right = 0, left = 0;
unsigned int r = 0;
int tempcount = 0;
while (tempcount < count)
{
r = square % 10;
right = (pow(10, tempcount) * r) + right;
square = square / 10;
tempcount++;
}
if (right != 0)
{
tempcount = 0;
while (square != 0)
{
r = square % 10;
left = (pow(10, tempcount) * r) + left;
square = square / 10;
tempcount++;
}
if (right + left == start)
{
haveNum = 1;
printf("%llu ", start);
}
}
start++;
}
if (haveNum == 0)
{
printf("INVALID RANGE");
}
printf("\n");
return 0;
}