I cannot find any good info on how to setup multi line macros. The problem I am having is that I need to use only macros (no functions) to compute factorials. When I use functions the code works but when I try to use macros I keep getting parse errors(it points to the macro I am using as the problem).
I left the function in there so people can understand what I am trying to achieve. If anyone has any advice or can point me to some resources that discuss how to set up multi line macros I would really appreciate it. Thank you in advance.Code:#include<stdio.h>
#include<math.h>
#define fact(x) do { \
int factorial=1; \
int k=1; \
factorial=factorial*k; \
k++; \
} while (k<=n)
#define comb(answer)(result/(input*last))
//int fact(int n);
main()
{
int n,k,x,result,diff,input,answer,last;
printf("Please enter a value for n \n");
scanf("%i",&n);
printf("Please enter a value for k \n");
scanf("%i",&k);
if (n<k)
printf("N must be larger than or equal to K \n");
else
{
result=fact(n);
input=fact(k);
diff=n-k;
last=fact(diff);
printf("The combination of %i things taken %i at a time is %i \n",n,k,comb(answer));
}
return 0;
}
//int fact(int n)
//{
// int k;
// int factorial=1;
// for(k=1; k<=n; k++)
// {
// factorial=factorial * k;
// }
//return factorial;
//}