Skip to content

Instantly share code, notes, and snippets.

@zinoviy23
Created October 6, 2021 10:09
Show Gist options
  • Save zinoviy23/27a24b5cbcc76b7626c58dc53737b7e3 to your computer and use it in GitHub Desktop.
Save zinoviy23/27a24b5cbcc76b7626c58dc53737b7e3 to your computer and use it in GitHub Desktop.
Решения задач с семинара 9 по операторам языка C
#include <stdio.h>
int main(void) {
int a;
int b;
int points_count = 1;
int in_triangles = 0;
int x;
int y;
double r2;
scanf("%d %d", &a, &b);
points_count += 2 * a + 2 * b;
r2 = b * b;
for (x = 1; x <= b; x++) {
for (y = 1; y <= b; y++) {
if (x * x + y * y <= r2) {
points_count++;
}
}
}
r2 = a * a;
for (x = 1; x <= a; x++) {
for (y = 1; y <= a; y++) {
if (x * x + y * y <= r2) {
points_count++;
}
}
}
for (x = 1; x <= b; x++) {
for (y = 1; y <= a; y++) {
if (a * x + b * y <= a * b) {
in_triangles++;
}
}
}
points_count += 2 * in_triangles;
printf("%d", points_count);
return 0;
}
#include <stdio.h>
int MAX_POWER = 31;
int main(void) {
int current;
int pows = 0;
int pow;
int i;
do {
scanf("%d", &current);
if (current == 0) break;
if ((current & (current - 1)) == 0) {
pows |= current;
}
} while (current != 0);
for (i = 1, pow = 0; pow < MAX_POWER && ((i & pows) != 0); i <<= 1, pow++);
if (pow == MAX_POWER) {
printf("All possible powers persists in list.");
} else {
printf("%d", pow);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment