fork(8) download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main(void) {
  5. int tests[] = { 1, 5, 10, 25, 100, 125, 250, 625, 1000 };
  6. int num_tests = sizeof(tests) / sizeof(tests[0]);
  7. int i;
  8.  
  9. for (i = 0; i < num_tests; ++i)
  10. {
  11. int x = tests[i];
  12. int n = (int)(log(x) / log(5)); // get n = log5(x), truncated to integer
  13. if (pow(5, n) == x) // test to see whether x == 5^n
  14. printf("%d is a power of 5\n", x);
  15. else
  16. printf("%d is not a power of 5\n", x);
  17. }
  18. return 0;
  19. }
  20.  
Success #stdin #stdout 0s 2248KB
stdin
Standard input is empty
stdout
1 is a power of 5
5 is a power of 5
10 is not a power of 5
25 is a power of 5
100 is not a power of 5
125 is a power of 5
250 is not a power of 5
625 is a power of 5
1000 is not a power of 5