Skip to content

Instantly share code, notes, and snippets.

@pmatos2000
Created May 29, 2022 21:12
Show Gist options
  • Save pmatos2000/ddc6b869c0d7716a1e81f839be103366 to your computer and use it in GitHub Desktop.
Save pmatos2000/ddc6b869c0d7716a1e81f839be103366 to your computer and use it in GitHub Desktop.
IEnumerable<int> GerarNumerosTriangulares(int n)
{
for (int i = 1; i <= n; i++)
{
var numero = i * (i + 1) / 2;
yield return numero;
}
}
foreach(var numero in GerarNumerosTriangulares(5))
{
Console.WriteLine(numero);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment