Created
October 16, 2021 20:31
-
-
Save ajpinedam/a8c305009bec732d8989bf5df83a2e4b to your computer and use it in GitHub Desktop.
Testing Twitter Preview
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
public class PowersOf2 | |
{ | |
static void Main() | |
{ | |
// Display powers of 2 up to the exponent of 8: | |
foreach (int i in Power(2, 8)) | |
{ | |
Console.Write("{0} ", i); | |
} | |
} | |
public static System.Collections.Generic.IEnumerable<int> Power(int number, int exponent) | |
{ | |
int result = 1; | |
for (int i = 0; i < exponent; i++) | |
{ | |
result = result * number; | |
yield return result; | |
} | |
} | |
// Output: 2 4 8 16 32 64 128 256 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment