Advertisement
Hiteshw11

Palindrome Using Generic Function

Nov 29th, 2024
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.21 KB | Source Code | 0 0
  1. void main()
  2. {
  3. var a = Factorial();
  4. print(a.calc<int>(5));
  5. }
  6.  
  7. class Factorial
  8. {
  9.  
  10.  
  11. T calc<T extends num>(T b)
  12. {
  13. num product=1;
  14. for(num i=b;i>0;i--)
  15. {
  16. product = product * i;
  17. }
  18. return product as T;
  19.  
  20. }
  21.  
  22. }
Tags: dart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement