1. Displaying calculation help ?

Code:
```#include <stdio.h>
#include "Boolean.h"
#include "combinatorics.h"
#include <limits.h>

/* For all the functions below, return TRUE if the
calculation is successful, FALSE if overflow occurs
Return the calculated value in the pass by reference
parameter provided
*/

Boolean calcFactorial (int n, int* nfact)
{
*nfact = 1;

while(n > 0)
{
*nfact = *nfact * n;
n--;
}

return TRUE;

}

Boolean calcCNR( int n, int r, int* cnr )
{
#define min(n,r)  (((n) < (r)) ? (n) : (r));

int multiplier = n;
int divisor = 1;
int k;

k = min(r, n - r);

*cnr = 1;
while (divisor <= k)
{
if(INT_MAX / multiplier < *cnr)
{
return FALSE;
}
else
{
*cnr = ((*cnr * multiplier) / divisor);

multiplier--;
divisor++;
}
}
return TRUE;
}

Boolean calcPNR( int cnr, int rfact, int* pnr )
{
if((INT_MAX / rfact) < cnr  &&  (INT_MAX / cnr) < rfact)
{
return FALSE;
}
else
{
*pnr = cnr * rfact;
}
return TRUE;
}```
Test Program
Code:
```#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include "Boolean.h"
#include "Combinatorics.h"

void displayResults( int n, int r,
Boolean cnrOK, Boolean pnrOK,
int cnr, int pnr )
{
if ( cnrOK )
{
printf("C(%d,%d) = %d   ", n, r, cnr);
}
else
{
printf("C(%d,%d) = OVFL\n");
}
if ( pnrOK )
{
printf("P(%d,%d) = %d\n", n, r, pnr);
}
else
{
printf("P(%d,%d) = OVFL\n");
}

}

void getData( int* n, int* r )
{
scanf ("%d %d",n,r);
assert ( *r >= 0 );
assert ( *n >= *r );
}

void main()
{
int n, r;
int cnr = 0, pnr = 0;
int rfact;
Boolean cnrOK, pnrOK, factOK;

printf("Enter two values > 0\n");

getData(&n, &r);
calcCNR(n, r, &cnr);
if(cnrOK != TRUE)
{
pnrOK = FALSE;
}
else
{
calcFactorial(r, &rfact);
}
if(factOK != TRUE)
{
pnrOK = FALSE;
}
else
{
calcPNR(cnr, rfact, &pnr);
}

displayResults( n,r, cnrOK, pnrOK, cnr, pnr );
}```
Suppose to look:
C(18,13) = 8568 P(18,13) = OVFL
C(40,10) = OVFL P(40,10) = OVFL
But mine looks:
C(18,13) = 8568 P(1245056,1243068) = OVFL
C(40,10) = 76904685 P(1245056,1243068) = OVFL
Can someone help me fix this please ?

2. Well for starters, main does NOT return void. It returns an int. Always. Read the FAQ for more, but change it in your code.

Next off, your indentation is absolutely horrible, and I just don't feel like formatting the whole thing for you.

Quzah.

3. Code:
```#include <stdio.h>
#include "Boolean.h"
#include "combinatorics.h"
#include <limits.h>

/* For all the functions below, return TRUE if the
calculation is successful, FALSE if overflow occurs
Return the calculated value in the pass by reference
parameter provided
*/

Boolean calcFactorial (int n, int* nfact)
{
*nfact = 1;

while(n > 0)
{
*nfact = *nfact * n;
n--;
}
return TRUE;
}

Boolean calcCNR( int n, int r, int* cnr )
{
#define min(n,r)  (((n) < (r)) ? (n) : (r));

int multiplier = n;
int divisor = 1;
int k;

k = min(r, n - r);

*cnr = 1;
while (divisor <= k)
{
if(INT_MAX / multiplier < *cnr)
{
return FALSE;
}
else
{
*cnr = ((*cnr * multiplier) / divisor);
multiplier--;
divisor++;
}
}
return TRUE;
}

Boolean calcPNR( int cnr, int rfact, int* pnr )
{
if((INT_MAX / rfact) < cnr  &&  (INT_MAX / cnr) < rfact)
{
return FALSE;
}
else
{
*pnr = cnr * rfact;
}
return TRUE;
}```
Test Program
Code:
```#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include "Boolean.h"
#include "Combinatorics.h"

void displayResults( int n, int r, Boolean cnrOK, Boolean pnrOK, int cnr, int pnr )
{
if ( cnrOK )
{
printf("C(%d,%d) = %d   ", n, r, cnr);
}
else
{
printf("C(%d,%d) = Overflow\n");
}
if ( pnrOK )
{
printf("P(%d,%d) = %d\n", n, r, pnr);
}
else
{
printf("P(%d,%d) = Overflow\n");
}
}

void getData( int* n, int* r )
{
scanf ("%d %d",n,r);
assert ( *r >= 0 );
assert ( *n >= *r );
}

int main()
{
int n, r;
int cnr = 0, pnr = 0;
int rfact;
Boolean cnrOK, pnrOK, factOK;

printf("Enter two values > 0\n");

getData(&n, &r);
calcCNR(n, r, &cnr);
if(cnrOK != TRUE)
{
pnrOK = FALSE;
}
else
{
calcFactorial(r, &rfact);
}
if(factOK != TRUE)
{
pnrOK = FALSE;
}
else
{
calcPNR(cnr, rfact, &pnr);
}
displayResults( n,r, cnrOK, pnrOK, cnr, pnr );
}```
Suppose to look:

C(18,13) = 8568 P(18,13) = OVFL
C(40,10) = OVFL P(40,10) = OVFL

But mine looks:

C(18,13) = 8568 P(1245056,1243068) = OVFL
C(40,10) = 76904685 P(1245056,1243068) = OVFL
Sorry for the identation problem. My problem still stays. Help please.

4. Code:
```int main()
{
int n, r;
int cnr = 0, pnr = 0;
int rfact;
Boolean cnrOK, pnrOK, factOK;

printf("Enter two values > 0\n");

getData(&n, &r);
? = calcCNR(n, r, &cnr);   if(cnrOK != TRUE)
{
pnrOK = FALSE;
}
else
{
? = calcFactorial(r, &rfact);   }
if(factOK != TRUE)
{
pnrOK = FALSE;
}
else
{
? = calcPNR(cnr, rfact, &pnr);
}
displayResults( n,r, cnrOK, pnrOK, cnr, pnr );
}```
look at your properly, u are returning the boolean varibale from all the function factorial . calcCNR and calcPNR but you are not storing the return value in the main function when it is called.

s.s.harish