A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
11
Task/Factorial/Dart/factorial-1.dart
Normal file
11
Task/Factorial/Dart/factorial-1.dart
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
int fact(int n) {
|
||||
if(n<0) {
|
||||
throw new IllegalArgumentException('Argument less than 0');
|
||||
}
|
||||
return n==0 ? 1 : n*fact(n-1);
|
||||
}
|
||||
|
||||
main() {
|
||||
print(fact(10));
|
||||
print(fact(-1));
|
||||
}
|
||||
15
Task/Factorial/Dart/factorial-2.dart
Normal file
15
Task/Factorial/Dart/factorial-2.dart
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
int fact(int n) {
|
||||
if(n<0) {
|
||||
throw new IllegalArgumentException('Argument less than 0');
|
||||
}
|
||||
int res=1;
|
||||
for(int i=1;i<=n;i++) {
|
||||
res*=i;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
main() {
|
||||
print(fact(10));
|
||||
print(fact(-1));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue