31 lines
958 B
C
31 lines
958 B
C
#include <stdio.h>
|
|
|
|
unsigned int multiply(unsigned int a, unsigned int b);
|
|
unsigned int power(unsigned int n, unsigned int m);
|
|
|
|
int main()
|
|
{
|
|
extern void initialise_monitor_handles(void);
|
|
initialise_monitor_handles();
|
|
|
|
unsigned int n[] = {0, 1, 0, 1, 2000, 2 , 7, 4294967295u, 3 };
|
|
unsigned int m[] = {0, 0, 1, 1, 2, 31 , 11, 1 , 20 };
|
|
unsigned int r[] = {1, 1, 0, 1, 4000000, 0x80000000u, 1977326743, 4294967295u, 3486784401u};
|
|
|
|
for (size_t i = 0; i != sizeof(n)/sizeof(n[0]); i++)
|
|
{
|
|
printf("%u ^ %u: ", n[i], m[i]);
|
|
unsigned int result = power(n[i], m[i]);
|
|
unsigned int correct = r[i];
|
|
if (result != correct)
|
|
{
|
|
printf("Failed, function returned %u but the correct answer is %u\n", result, correct);
|
|
}
|
|
else
|
|
{
|
|
printf("Passed, %u\n", result);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|