This blog is under construction

## Tuesday, 9 July 2013

### C program to print the four digit numbers whose sum of squares of first half and second half of the number equals the same number

Write a C program to print the four digit numbers whose sum of squares of first half and second half of the number equals the same number.

#include <stdio.h>
int main() {
int i = 1000, fhalf, shalf, fsquare, ssquare;

/* print if square of 1st and 2nd half are same */
while (i < 10000) {
shalf = i % 100;
fhalf = i / 100;
ssquare = shalf * shalf;
fsquare = fhalf * fhalf;
if (fsquare == ssquare) {
printf("%d => (%d)^2 equals to (%d)^2\n",
i, fhalf, shalf);
}
i++;
}
return 0;
}

Output:
jp@jp-VirtualBox:~/\$ ./a.out
1010 => (10)^2 equals to (10)^2
1111 => (11)^2 equals to (11)^2
1212 => (12)^2 equals to (12)^2
1313 => (13)^2 equals to (13)^2
1414 => (14)^2 equals to (14)^2
1515 => (15)^2 equals to (15)^2
1616 => (16)^2 equals to (16)^2
1717 => (17)^2 equals to (17)^2
1818 => (18)^2 equals to (18)^2
1919 => (19)^2 equals to (19)^2
2020 => (20)^2 equals to (20)^2
2121 => (21)^2 equals to (21)^2
2222 => (22)^2 equals to (22)^2
2323 => (23)^2 equals to (23)^2
2424 => (24)^2 equals to (24)^2
2525 => (25)^2 equals to (25)^2
2626 => (26)^2 equals to (26)^2
2727 => (27)^2 equals to (27)^2
2828 => (28)^2 equals to (28)^2
2929 => (29)^2 equals to (29)^2
3030 => (30)^2 equals to (30)^2
3131 => (31)^2 equals to (31)^2
3232 => (32)^2 equals to (32)^2
3333 => (33)^2 equals to (33)^2
3434 => (34)^2 equals to (34)^2
3535 => (35)^2 equals to (35)^2
3636 => (36)^2 equals to (36)^2
3737 => (37)^2 equals to (37)^2
3838 => (38)^2 equals to (38)^2
3939 => (39)^2 equals to (39)^2
4040 => (40)^2 equals to (40)^2
4141 => (41)^2 equals to (41)^2
4242 => (42)^2 equals to (42)^2
4343 => (43)^2 equals to (43)^2
4444 => (44)^2 equals to (44)^2
4545 => (45)^2 equals to (45)^2
4646 => (46)^2 equals to (46)^2
4747 => (47)^2 equals to (47)^2
4848 => (48)^2 equals to (48)^2
4949 => (49)^2 equals to (49)^2
5050 => (50)^2 equals to (50)^2
5151 => (51)^2 equals to (51)^2
5252 => (52)^2 equals to (52)^2
5353 => (53)^2 equals to (53)^2
5454 => (54)^2 equals to (54)^2
5555 => (55)^2 equals to (55)^2
5656 => (56)^2 equals to (56)^2
5757 => (57)^2 equals to (57)^2
5858 => (58)^2 equals to (58)^2
5959 => (59)^2 equals to (59)^2
6060 => (60)^2 equals to (60)^2
6161 => (61)^2 equals to (61)^2
6262 => (62)^2 equals to (62)^2
6363 => (63)^2 equals to (63)^2
6464 => (64)^2 equals to (64)^2
6565 => (65)^2 equals to (65)^2
6666 => (66)^2 equals to (66)^2
6767 => (67)^2 equals to (67)^2
6868 => (68)^2 equals to (68)^2
6969 => (69)^2 equals to (69)^2
7070 => (70)^2 equals to (70)^2
7171 => (71)^2 equals to (71)^2
7272 => (72)^2 equals to (72)^2
7373 => (73)^2 equals to (73)^2
7474 => (74)^2 equals to (74)^2
7575 => (75)^2 equals to (75)^2
7676 => (76)^2 equals to (76)^2
7777 => (77)^2 equals to (77)^2
7878 => (78)^2 equals to (78)^2
7979 => (79)^2 equals to (79)^2
8080 => (80)^2 equals to (80)^2
8181 => (81)^2 equals to (81)^2
8282 => (82)^2 equals to (82)^2
8383 => (83)^2 equals to (83)^2
8484 => (84)^2 equals to (84)^2
8585 => (85)^2 equals to (85)^2
8686 => (86)^2 equals to (86)^2
8787 => (87)^2 equals to (87)^2
8888 => (88)^2 equals to (88)^2
8989 => (89)^2 equals to (89)^2
9090 => (90)^2 equals to (90)^2
9191 => (91)^2 equals to (91)^2
9292 => (92)^2 equals to (92)^2
9393 => (93)^2 equals to (93)^2
9494 => (94)^2 equals to (94)^2
9595 => (95)^2 equals to (95)^2
9696 => (96)^2 equals to (96)^2
9797 => (97)^2 equals to (97)^2
9898 => (98)^2 equals to (98)^2
9999 => (99)^2 equals to (99)^2

See Also: