Skip to content

Instantly share code, notes, and snippets.

@wjlafrance
Created March 29, 2011 06:11
Show Gist options
  • Select an option

  • Save wjlafrance/891879 to your computer and use it in GitHub Desktop.

Select an option

Save wjlafrance/891879 to your computer and use it in GitHub Desktop.
/**
* Division Challenge - divide.c
* William LaFrance
* 2011 March 28
*/
#import <stdio.h>
#define null 0x0
int main() {
if (divide(50, 5, null) == 10) {
printf("Pass\n");
} else {
printf("Fail\n");
}
int remainder;
if (divide(54, 5, &remainder) == 10) {
printf("Pass\n");
} else {
printf("Fail\n");
}
if (remainder == 4) {
printf("Pass\n");
} else {
printf("Fail - Remainder is %d, should be 4\n", remainder);
}
return 1;
}
int divide(int numerator, int denominator, int *remainder) {
int retVal;
int _numerator = numerator;
for (retVal = 0; _numerator >= denominator; retVal++) {
_numerator -= denominator;
}
if (remainder != 0x00) {
*remainder = _numerator;
}
return retVal;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment