int main(int argc, char **argv) { importFunction addNumbers; double result; // Load DLL file HINSTANCE hinstLib = LoadLibrary(TEXT("Example.dll")); if (hinstLib == NULL) { printf("ERROR: unable to load DLL\n"); return 1; } // Get function pointer addNumbers = (importFunction)GetProcAddress(hinstLib, "AddNumbers"); if (addNumbers == NULL) { printf("ERROR: unable to find DLL function\n"); FreeLibrary(hinstLib); return 1; } // Call function. result = addNumbers(1, 2); // Unload DLL file FreeLibrary(hinstLib); // Display result printf("The result was: %f\n", result); return 0; }
int main () { int n; printf("Enter an integer to check Odd/Even\n"); scanf("%d", &n); oddEven(n); prime(); int a,b; printf ("Enter an integer 'a' \n"); scanf("%d", &a); printf ("Enter an integer 'b' \n"); scanf("%d", &b); printf ("a/b =%f\n",division(a,b)); printf("Enter the number of integers you want to add\n"); scanf("%d", &n); addNumbers(&n); int *i; i = (int *) malloc(sizeof(int)); *i=200; printf("The content of the memory address %p is %d\n", i,*i); return 0; }
int main(){ if(!out) { addNumbers(10, 20); std::cout << 1 << std::endl; } else { std::cout << 2 << std::endl; } }
int main(int argc, char *argv[]) { printf("sum = %d\n", addnum(7,3)); printf("sum = %d\n", addNumbers(5, 4)); return 0; }
void checkForAddOperation(char operator1, char addOperator, double &number2, double &number1) { if (operator1 == addOperator) { cin >> number2; number1 = addNumbers(number1, number2); }
bignum subtractNumbers(const bignum &bn1, const bignum &bn2) { if (bn1.getBase() != bn2.getBase()) return subtractNumbers(bn1, bn2.getConverted(bn1.getBase())); int base = bn1.getBase(); bignum difference; difference.setBase(base); //evaluate the numbers being of equal absolute value if (bn1.absolute() == bn2.absolute()) { // -12 - 12 ---> -(12 + 12) if (bn1.isNegative() && !bn2.isNegative()) { bignum temp = addNumbers(bn1.absolute(), bn2.absolute()); temp.setNegative(); temp.updateDigits(); return temp; } // 12 - -12 ---> 12 + 12 if (!bn1.isNegative() && bn2.isNegative()) return addNumbers(bn1.absolute(), bn2.absolute()); // -12 - -12 ---> 0 if (bn1.isNegative() && bn2.isNegative()) { bignum temp; temp.setBase(base); return temp; } } //evaluate the numbers if absolute first is larger than absolute second if (bn1.absolute() > bn2.absolute()) { // -12 - 8 ---> -(12 + 8) if (bn1.isNegative() && !bn2.isNegative()) { bignum temp = addNumbers(bn1.absolute(), bn2.absolute()); temp.setNegative(); temp.updateDigits(); return temp; } // 12 - -8 ---> 12 + 8 if (!bn1.isNegative()&& bn2.isNegative()) return addNumbers(bn1.absolute(), bn2.absolute()); // -12 - -8 ---> -(12 - 8) if (bn1.isNegative() && bn2.isNegative()) { bignum temp = subtractNumbers(bn1.absolute(), bn2.absolute()); temp.setNegative(); temp.updateDigits(); return temp; } } //evaluate the numbers if absolute first is smaller than absolute second if (bn1.absolute() < bn2.absolute()) { // 8 - 12 ---> -(12 - 8) if (!bn1.isNegative()&& !bn2.isNegative()) { bignum temp = subtractNumbers(bn2.absolute(), bn1.absolute()); temp.setNegative(); temp.updateDigits(); return temp; } // -8 - 12 ---> -(8 + 12) if (bn1.isNegative() && !bn2.isNegative()) { bignum temp = addNumbers(bn1.absolute(), bn2.absolute()); temp.setNegative(); temp.updateDigits(); return temp; } // 8 - -12 ---> 8 + 12 if (!bn1.isNegative() && bn2.isNegative()) return addNumbers(bn1.absolute(), bn2.absolute()); // -8 - -12 ---> (12 - 8) if (bn1.isNegative() && bn2.isNegative()) return subtractNumbers(bn2.absolute(), bn1.absolute()); } int carry = 0; int digits = 0; int decimal = 0; //bool carry_negative = false; //sets decimal and digit values to the highest of each number decimal = (bn1.getDecimalCount() > bn2.getDecimalCount() ? bn1.getDecimalCount() : bn2.getDecimalCount()); digits = (bn1.getDigitCount() > bn2.getDigitCount() ? bn1.getDigitCount() + 1 : bn2.getDigitCount() + 1); for (int i = (ONES_PLACE - decimal); i < digits + 1 && i >= 0; i++) { if (i >= MAXDIGITS) throw error_handler(__FILE__, __LINE__, "The value being calculated is too large for the settings provided"); int tempNumber = bn1.getDigit(i) - bn2.getDigit(i); tempNumber -= carry; if (tempNumber < 0) { tempNumber += base; carry = 1; } else carry = 0; difference.setDigit(i, tempNumber); } difference.updateDigits(); difference.setBase(base); return difference; }
bignum addNumbers(const bignum &bn1, const bignum &bn2) { if (bn1.getBase() != bn2.getBase()) return addNumbers(bn1, bn2.getConverted(bn1.getBase())); if (bn1.absolute() == bn2.absolute()) { // -12 + 12 or 12 + -12 ---> 0 if (bn1.isNegative() != bn2.isNegative()) { bignum temp; temp.setBase(bn1.getBase()); return temp; } // -12 + -12 ---> -(12 + 12) if (bn1.isNegative() && bn2.isNegative()) { bignum temp(addNumbers(bn1.absolute(), bn2.absolute())); temp.setNegative(); temp.updateDigits(); return temp; } } if (bn1.absolute() > bn2.absolute()) { // -12 + 8 ---> -(12 - 8) if (bn1.isNegative() && !bn2.isNegative()) { bignum temp = subtractNumbers(bn1.absolute(), bn2.absolute()); temp.setNegative(); temp.updateDigits(); return temp; } // 12 + -8 ---> 12 - 8 if (!bn1.isNegative() && bn2.isNegative()) return subtractNumbers(bn1.absolute(), bn2.absolute()); // -12 + -8 ---> -(12 + 8) if (bn1.isNegative()&& bn2.isNegative()) { bignum temp = addNumbers(bn1.absolute(), bn2.absolute()); temp.setNegative(); temp.updateDigits(); return temp; } } if (bn1.absolute() < bn2.absolute()) { // -8 + 12 ---> 12 - 8 if (bn1.isNegative() && !bn2.isNegative()) { bignum temp = subtractNumbers(bn2.absolute(), bn1.absolute()); temp.updateDigits(); return temp; } // 8 + -12 ---> 8 - 12 if (!bn1.isNegative() && bn2.isNegative()) return subtractNumbers(bn1.absolute(), bn2.absolute()); // -8 + -12 ---> -(8 + 12) if (bn1.isNegative() && bn2.isNegative()) { bignum temp = addNumbers(bn1.absolute(), bn2.absolute()); temp.setNegative(); temp.updateDigits(); return temp; } } int carry = 0; int digits = 0; int decimal = 0; //sets decimal and digit values to the highest of each number decimal = (bn1.getDecimalCount() > bn2.getDecimalCount() ? bn1.getDecimalCount() : bn2.getDecimalCount()); digits = (bn1.getDigitCount() > bn2.getDigitCount() ? bn1.getDigitCount() + 1 : bn2.getDigitCount() + 1); bignum sum; int base = bn1.getBase(); for (int i = (ONES_PLACE - decimal); i < digits + 1 ; i++) { if (i >= MAXDIGITS) throw error_handler(__FILE__, __LINE__, "The value being calculated is too large for the settings provided"); int tempNumber = bn1.getDigit(i) + bn2.getDigit(i); tempNumber += carry; if (tempNumber>(base - 1)) { tempNumber -= base; carry = 1; } else carry = 0; sum.setDigit(i, tempNumber); } sum.updateDigits(); sum.setBase(base); return sum; }
void bignum::operator ++ (int n) { bignum one(1); one.setBase(base); *this = addNumbers(*this, one); }