@nakov/

do-while-loop-power-of-2-calculation-csharp

C#

Calculate power of 2 using a do-while loop in C#

fork
loading
Files
  • main.cs
  • main.exe

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.7184158490554704","path":"main.cs","file":{"path":"main.cs","content":{"asEncoding":{"base64":"dXNpbmcgU3lzdGVtOwoKY2xhc3MgUG93ZXJPZjJDYWxjdWxhdGlvbiB7CiAgICBwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpIHsKICAgICAgICBpbnQgbnVtID0gMSwgY291bnQgPSAwOwogICAgICAgIGRvCiAgICAgICAgewogICAgICAgICAgICBjb3VudCsrOwogICAgICAgICAgICBudW0gPSBudW0gKiAyOwogICAgICAgIH0gd2hpbGUgKG51bSA8PSAxMDAwMDAwMDAwKTsKICAgICAgICBDb25zb2xlLldyaXRlTGluZSgiMl57MH0gPSB7MX0iLCBjb3VudCwgbnVtKTsKICAgIH0KfQo="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
using System;

class PowerOf2Calculation {
    public static void Main() {
        int num = 1, count = 0;
        do
        {
            count++;
            num = num * 2;
        } while (num <= 1000000000);
        Console.WriteLine("2^{0} = {1}", count, num);
    }
}