gcd(x, y) = (y == 0) ? x : gcd(y, x mod y)
Your function should be callable from C as in this example:
#include <stdio.h>
#include <stdint.h>
#include <assert.h>
uint64_t gcd(uint64_t x, uint64_t y);
int main() {
assert(gcd(309,66) == 3);
assert(gcd(66, 309) == 3);
assert(gcd(3113041662, 11570925) == 462837);
assert(gcd(427366239731, 4273650023214) == 6499);
assert(gcd(427366239731687, 4268765973650023214) == 1);
puts("All tests passed");
return 0;
}
0x3d744b26 would be turned into 0x264b743d. The function should accept a pointer to the integer to be converted. Here is a sample calling program in C:
#include <stdio.h>
#include <stdint.h>
#include <assert.h>
void byteswap(uint32_t *x);
int main() {
uint32_t x = 0x3d744b26;
byteswap(&x);
assert(x == 0x264b743d);
puts("All tests passed");
return 0;
}
#include <stdio.h>
#include <stdint.h>
#include <assert.h>
uint32_t onebits(int32_t x);
int main() {
assert(onebits(0) == 0);
assert(onebits(-1) == 32);
assert(onebits(0x264b743d) == 16);
assert(onebits(0x12345678) == 13);
puts("All tests passed");
return 0;
}
#include <stdio.h>
#include <stdint.h>
#include <assert.h>
double power_of_difference(double x, double y, int32_t b);
int main() {
assert(power_of_difference(5, 5, 20) == 0);
assert(power_of_difference(50, 45, 10) == 9765625);
assert(power_of_difference(206, 204, 20) == 1048576);
assert(power_of_difference(206, 204, -3) == 0.125);
assert(power_of_difference(-30, -26, -4) == 0.00390625);
assert(power_of_difference(16.5, 15, 3) == 3.375);
puts("All tests passed");
return 0;
}