Advertisement
Hiteshw11

Dart program that takes a list of integers and prints the sum of all elements in the list.

Nov 16th, 2024
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.29 KB | Source Code | 0 0
  1. //Dart program that takes a list of integers and prints the sum of all elements in the list.
  2.  
  3. void main() {
  4.   List<int> abc =[2,3,4,5,6];
  5.  print( numsum(abc));
  6. }
  7.  
  8.  
  9. int numsum(List<int> nums)
  10. {
  11. int sum=0;
  12.  
  13. for(int i =0;i<nums.length;i++)
  14.  {
  15.   sum = sum+ nums[i];
  16. }
  17. return sum;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement