#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 100
#define SAVE_FACTOR(fact, exp) { if (exp > 0) \
factors[count] = fact, \
exps[count++] = i; \
}
void main(void)
{
unsigned long factors[MAXSIZE];
unsigned long exps[MAXSIZE];
unsigned long n, work;
int count = 0;
int i, k;
char line[100], *dummy;
printf("\nFactorization by Division Program");
printf("\n=================================");
printf("\n\nInput a positive integer --> ");
gets(line);
n = strtoul(line, &dummy, 10);
for (i=0,work=n; (work & 0x01UL)==0 && work>1; work>>=1,i++)
;
SAVE_FACTOR(2, i);
for (k = 3; k <= work; k += 2) {
for (i = 0; work % k == 0 && work > 1; work /= k, i++)
;
SAVE_FACTOR(k, i);
}
printf("\n%ld = ", n);
for (i = 0; i < count; i++)
printf("%ld(%ld)", factors[i], exps[i]);
}
I want to answer the fuction
#define SAVE_FACTOR(fact, exp) { if (exp > 0) \
factors[count] = fact, \
exps[count++] = i; \
Instead of:
void SAVE_FACTOR (fact,exp)
{
if (exp>0)
{
factors[count]=fact;
exps[count++]=i;
}
}
Which the efficiency of the two?
[EDIT: Added code tags, separated code#1 & code#2]