-
Notifications
You must be signed in to change notification settings - Fork 0
/
23CS01017_Assign3_Q6.c
54 lines (50 loc) · 1.22 KB
/
23CS01017_Assign3_Q6.c
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
#include <stdio.h>
#include <math.h>
int main()
{
int n, len = 0, temp1, temp2, i = 0;
printf("Enter the number: ");
scanf("%d", &n);
int num = n * n;
int num1 = num;
printf("The square of %d is %d", n, num);
while (num1 > 0)
{
num1 = num1 / 10;
len++;
}
int len1 = len;
len = (len / 2) + (len % 2);
for (; len > 0; len--)
{
double div = pow(10, len);
temp1 = num / div;
temp2 = num - temp1 * div;
if (temp1 + temp2 == n)
{
printf("\nAs %d + %d = %d", temp1, temp2, n);
printf("\n%d is a KAPREKAR NUMBER", n);
i++;
break;
}
}
if (i == 0)
{
for (; len < len1; len++)
{
double div = pow(10, len);
temp1 = num / div;
temp2 = num - temp1 * div;
if (temp1 + temp2 == n)
{
printf("\nAs %d + %d = %d", temp1, temp2, n);
printf("\n%d is a KAPREKAR NUMBER", n);
i++;
break;
}
}
}
if (i == 0)
printf("\n%d is NOT a KAPREKAR NUMBER", n);
return 0;
}