Code
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5
6namespace NumnerOutput
7{
8 class Program
9 {
10 static void Main(string[] args)
11 {
12 List<double> d = Get2PowArray(10);
13 foreach (double dd in d)
14 {
15 Console.WriteLine(dd.ToString());
16 }
17 Console.ReadKey();
18 }
19 public static double pow2(double n)
20 {
21 double i = 0;
22
23 while (Math.Pow(2, i) < n)
24 {
25 i++;
26 }
27 if (Math.Pow(2, i) > n)
28 return --i;
29 else
30 return i;
31 }
32 public static List<double> Get2PowArray(double n)
33 {
34 double temp = n;
35 List<double> arrayList = new List<double>();
36 while (temp >= 1)
37 {
38 double maxIndex = pow2(temp);
39 temp -= Math.Pow(2,maxIndex);
40 arrayList.Add(Math.Pow(2,maxIndex));
41 }
42 return arrayList;
43 }
44
45 }
46}
47
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5
6namespace NumnerOutput
7{
8 class Program
9 {
10 static void Main(string[] args)
11 {
12 List<double> d = Get2PowArray(10);
13 foreach (double dd in d)
14 {
15 Console.WriteLine(dd.ToString());
16 }
17 Console.ReadKey();
18 }
19 public static double pow2(double n)
20 {
21 double i = 0;
22
23 while (Math.Pow(2, i) < n)
24 {
25 i++;
26 }
27 if (Math.Pow(2, i) > n)
28 return --i;
29 else
30 return i;
31 }
32 public static List<double> Get2PowArray(double n)
33 {
34 double temp = n;
35 List<double> arrayList = new List<double>();
36 while (temp >= 1)
37 {
38 double maxIndex = pow2(temp);
39 temp -= Math.Pow(2,maxIndex);
40 arrayList.Add(Math.Pow(2,maxIndex));
41 }
42 return arrayList;
43 }
44
45 }
46}
47