Нужно найти ошибку. Перевод из 10СС в 2СС - C#
Формулировка задачи:
Помогите найти ошибку. Перевод из 10СС в 2СС
Вот два кода:
Помогите исправить одну программу.Спасибо
//выводит числа правильно, но нужно в обратном порядке
public static void schet()
{
int a = Convert.ToInt32(Console.ReadLine());
string s;
while (a > 1)
{
Console.Write(a % 2);
a = a / 2;
}
s = Convert.ToString(a);
s = new string (s.Reverse().ToArray());
Console.WriteLine(s);
}
public static void Main()
{
schet();
Console.ReadLine();
}
}//нужно в обратном порядке в каком-н из кодов это сделать
public static void schet()
{
int a = Convert.ToInt32(Console.ReadLine());
string s;
while (a > 1)
{
Console.Write(a % 2);
a = a / 2;
}
s = Convert.ToString(a);
char[] array = s.ToCharArray();
int last = array.Length -1;
for (int i = last;i>= 0;i--)
{
Console.Write(array[i]);
}
}
public static void Main()
{
schet();
Console.ReadLine();
}Решение задачи: «Нужно найти ошибку. Перевод из 10СС в 2СС»
textual
Листинг программы
public static void schet()
{
int a = Convert.ToInt32(Console.ReadLine());
Stack<int> st = new Stack<int>();
while (a > 1)
{
st.Push(a % 2);
a = a / 2;
}
st.Push(a % 2);
Console.WriteLine(string.Join("", st));
}