Skip to content

Commit b42795e

Browse files
committed
Feat: Solving exercise 4 of the third challenge
1 parent 5994009 commit b42795e

File tree

1 file changed

+25
-0
lines changed
  • OOP/Creating my first application/3) Listas e Loops

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Criar um programa que calcula a soma de todos os elementos inteiros em uma lista
2+
using System;
3+
using System.Collections.Generic;
4+
5+
class Program {
6+
7+
// Função que faz a soma de todos os elementos na lista
8+
static int Soma(List<int> numeros){
9+
int soma = 0;
10+
11+
foreach(int numero in numeros){
12+
soma += numero;
13+
}
14+
15+
return soma;
16+
}
17+
18+
static void Main(string[] args){
19+
List<int> numeros = new List<int>{3, 10, 9, 2, 49};
20+
21+
int soma = Soma(numeros);
22+
23+
Console.WriteLine($"A soma de todos os elementos da lista é: {soma}");
24+
}
25+
}

0 commit comments

Comments
 (0)