Advertisement
Hiteshw11

Sum Of List Elements

Nov 24th, 2024
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.24 KB | Source Code | 0 0
  1. // Sum of List Elements
  2.  
  3.  
  4. void main()
  5. {
  6.  List<int> list1 = [1,2,3,4,5];
  7.  print(sumList(list1));
  8. }
  9.  
  10. int sumList(List<int> list1)
  11. {
  12.   int sum=0;
  13.   for(int i=0;i<list1.length;i++)
  14.   {
  15.     sum=sum+list1[i];
  16.   }
  17.   return sum;
  18. }
  19.  
Tags: dart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement