我在C#中需要帮助-程序将询问用户一些数字并进行数字排序,例如,对于数字4352,将接收到输出2534。
我该怎么做?我需要使用“ while”和“ switch”以及%
{
case 1:
Console.WriteLine("Please select a math action to apply + , - , * , / ");
string sign = Console.ReadLine();
Console.WriteLine("Please entre a number to multiply:");
int num = int.Parse(Console.ReadLine());
int firstnumber = 0;
switch (sign)
{
case "+":
Console.WriteLine(firstnumber += num);
break;
case "-":
Console.WriteLine(firstnumber-=num);
break;
case "/":
Console.WriteLine(firstnumber/=num);
break;
case "*":
Console.WriteLine(firstnumber*= num);
break;
case "=":
double result = firstnumber;
Console.WriteLine(result);
break;
default:
Console.WriteLine("error please entre aviable context");
break;
}
break;
case 2:
Console.WriteLine("write down a number");
string word2 = Console.ReadLine();
int num2 = int.Parse(word2);
while (num2 > 0)
{
int Opertor = 10;
Console.WriteLine(num2 % Opertor);
}
break;
这是我到目前为止的内容
您需要根据输入内容编写用于反转字符串或数字的函数。
下面是反转数字的代码。
int Number = int.Parse(Console.ReadLine());
int Reverse = 0;
while(Number>0)
{
int remainder = Number % 10;
Reverse = (Reverse * 10) + remainder;
Number = Number / 10;
}
Console.WriteLine("Reverse No. is {0}",Reverse);
和反向字符串
string str = "", reverse = "";
int Length = 0;
Console.WriteLine("Enter a Word");
str = Console.ReadLine();
Length = str.Length - 1;
while(Length>=0)
{
reverse = reverse + str[Length];
Length--;
}
Console.WriteLine("Reverse word is {0}",reverse);