diff --git a/data/broadcast.c b/data/broadcast.c new file mode 100644 index 0000000..b2129e7 --- /dev/null +++ b/data/broadcast.c @@ -0,0 +1,17 @@ +#include + +int main() { + unsigned int ip[4]; + unsigned int netmask[4]; + unsigned int broadcast[4] = {0, 0, 0, 0}; + int i; + + scanf("%d.%d.%d.%d", &ip[0], &ip[1], &ip[2], &ip[3]); + scanf("%d.%d.%d.%d", &netmask[0], &netmask[1], &netmask[2], &netmask[3]); + for (i = 0; i < 4; ++i) { + broadcast[i] = (ip[i] & netmask[i]) | (~netmask[i] & 255); + } + for (i = 0; i < 3; ++i) + printf("%d.", broadcast[i]); + printf("%d", broadcast[3]); +} diff --git a/data/complement.c b/data/complement.c new file mode 100644 index 0000000..b1c026d --- /dev/null +++ b/data/complement.c @@ -0,0 +1,15 @@ +#include + +int main() { + int i; + char y; + scanf("%hhd", &y); + + if (y < 0) + y = ~(-y) + 1; + + for (i = 7; i >= 0; --i) { + printf("%d", (y >> i) & 1); + } + return 0; +} diff --git a/data/size.c b/data/size.c new file mode 100644 index 0000000..5383565 --- /dev/null +++ b/data/size.c @@ -0,0 +1,29 @@ +#include +#include + +int main() { + char s; + int len_f = 0; + int len_d = 0; + int len_ld = 0; + s = getchar(); + + float xf = 0.5; + double xd = 0.5; + long double xld = 0.5; + + for (; (float)1.0 + xf != (float)1.0; ++len_f, xf /= 2); + for (; 1.0 + xd != 1.0; ++len_d, xd /= 2); + for (; 1.0 + xld != 1.0; ++len_ld, xld /= 2); + + if (s == 'f') { + printf("%d", len_f); + } + if (s == 'd') { + printf("%d", len_d); + } + if (s == 'l') { + printf("%d", len_ld); + } + +}