Created
March 29, 2011 06:11
-
-
Save wjlafrance/891879 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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