Last active
September 2, 2021 08:27
-
-
Save mhmadip/aef707cb8b2a422a7256e7a43bbe175d to your computer and use it in GitHub Desktop.
Sum of odd and even numbers and search for a specific number inside the list
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
import 'dart:io'; | |
int sumEven(List li) { | |
int sum = 0; | |
for (var i in li) { | |
if (i % 2 == 0) { | |
sum = sum + i; | |
} | |
} | |
return sum; | |
} | |
int sumOdd(List li) { | |
int sum = 0; | |
for (var i in li) { | |
if (i % 2 == 1) { | |
sum = sum + i; | |
} | |
} | |
return sum; | |
} | |
void main() { | |
var list = []; | |
for (int i = 100; i > 0; i--) { | |
list.add(i); | |
} | |
print(sumEven(list)); | |
print(sumOdd(list)); | |
int input = int.parse(stdin.readLineSync()); | |
bool valid=false; | |
for(var i in list){ | |
if (i== input){ | |
print("valid"); | |
valid=true; | |
} | |
} | |
if (valid!=true){ | |
print("not valid"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment