107 286
Assignments Done
97.9%
Successfully Done
In March 2023

# Answer to Question #272085 in C# for chi

Question #272085

Write a program that reverses the input number n. Formulate an equation to come up with the answer:

(Apply the three loop statements in your solutions) Sample input/output dialogue:

Enter a number: 1238 Input data

Reverse number: 8321 Output value

1st Solution using- for loop

2nd Solution using- while loop

3rd Solution using- do while loop

1
2021-11-28T05:26:47-0500
class Program
{
public static void Main()
{

Console.Write("Enter a number: ");

string output = ReverseWithDoWhile(input);
Console.WriteLine(\$"Reverse number: {output}");

}

public static string ReverseWithFor(string text)
{
StringBuilder output = new StringBuilder(text.Length);

for (int i = text.Length - 1; i >= 0; i--)
output.Append(text[i]);

return output.ToString(); ;
}

public static string ReverseWithWhile(string text)
{
StringBuilder output = new StringBuilder(text.Length);

int i = text.Length - 1;
while (i >= 0)
{
output.Append(text[i]);
i--;
}

return output.ToString(); ;
}

public static string ReverseWithDoWhile(string text)
{
StringBuilder output = new StringBuilder(text.Length);

int i = text.Length - 1;
do
{
output.Append(text[i]);
} while (--i >= 0);

return output.ToString(); ;
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!