A regular number is a positive integer all of whose prime factors are in the set {2, 3, 5}. (1
is assumed to be regular.) Write a function regular that consumes a positive integer n and
prints out all regular numbers up to (and possibly including) n, one to a line, in increasing
order.
To submit: regular.c, regular-driver.c.
My regular.c contains
Code:
#include <math.h>
#include <stdio.h>
int regular(int n) {
int m = n;
while (n%5) {
m = m/5;
}
while (m%3) {
m = m/3;
}
while (m%2) {
m = m/2;
}
if (m == 1) {
printf("%d ", n);
return regular(n-1);
}
}
my regular-driver.c contains
Code:
#include <stdio.h>
#include "regular.h"
int main() {
regular(60);
return 0;
}
I don't have an error but once I run regular. Nothing happens no output.
I believe it is because it never reaches the if statement.
I know that 60 is a regular number because 5*3*2*2 = 60
So it should atleast printf that 60 is regular.
Any help is appreciated.