|
@ -3,6 +3,7 @@ |
|
|
#include <limits.h> |
|
|
#include <limits.h> |
|
|
#include <stdlib.h> |
|
|
#include <stdlib.h> |
|
|
|
|
|
|
|
|
|
|
|
// addition for two integer inputs (no decimal number) |
|
|
int* addition_integer(int num1, int num2) { |
|
|
int* addition_integer(int num1, int num2) { |
|
|
if ((num2 > 0 && num1 > INT_MAX - num2) || (num2 < 0 && num1 < INT_MIN - num2)) { |
|
|
if ((num2 > 0 && num1 > INT_MAX - num2) || (num2 < 0 && num1 < INT_MIN - num2)) { |
|
|
return NULL; |
|
|
return NULL; |
|
@ -12,18 +13,21 @@ int* addition_integer(int num1, int num2) { |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// addition for two double inputs (decimal number) |
|
|
double* addition_double(double num1, double num2) { |
|
|
double* addition_double(double num1, double num2) { |
|
|
double* result = malloc(sizeof(double)); |
|
|
double* result = malloc(sizeof(double)); |
|
|
*result = num1+num2; |
|
|
*result = num1+num2; |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// addition for two float inputs (decimal number) |
|
|
float* addition_float(float num1, float num2) { |
|
|
float* addition_float(float num1, float num2) { |
|
|
float* result = malloc(sizeof(float)); |
|
|
float* result = malloc(sizeof(float)); |
|
|
*result = num1+num2; |
|
|
*result = num1+num2; |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// addition for two long inputs (no decimal number) |
|
|
long* addition_long(long num1, long num2) { |
|
|
long* addition_long(long num1, long num2) { |
|
|
long* result = malloc(sizeof(long)); |
|
|
long* result = malloc(sizeof(long)); |
|
|
*result = num1+num2; |
|
|
*result = num1+num2; |
|
|