Created
January 19, 2023 04:59
-
-
Save LokieVikky/e299f36c5c8ea69dc00108b88b95c6f7 to your computer and use it in GitHub Desktop.
Calculator
This file contains 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
void main() { | |
Calculator calc = Calculator(); | |
int result = calc.add(6, 7); | |
print(result); | |
result = calc.sub(3, 5, 8); | |
print(result); | |
result = calc.mulitply(7, 3, 2); | |
print(result); | |
result = calc.modulus(7, 3); | |
print(result); | |
double result1 = calc.divide(7, 3); | |
print(result1); | |
List<int> resultList = calc.factor(70); | |
print(resultList.join(',')); | |
} | |
class Calculator { | |
int add(int num1, int num2) { | |
return num1 + num2; | |
} | |
int sub(int num1, int num2, int num3) { | |
return num1 - num2 - num3; | |
} | |
int mulitply(int num1, int num2, int num3) { | |
return num1 * num2 * num3; | |
} | |
int modulus(int num1, int num2) { | |
return num1 % num2; | |
} | |
double divide(int num1, int num2) { | |
return num1 / num2; | |
} | |
List<int> factor(int num1) { | |
List<int> factors = []; | |
for (int a = 1; a <= num1; a++) { | |
int b = num1 % a; | |
if (b == 0) { | |
factors.add(a); | |
} | |
} | |
return factors; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment