- Course
- Functions B
- Function to show an inverted string
Function to show an inverted string
Last updated:
8/23/2020
⁃
Difficulty:
Intermediate
Create a C# program that implements a function called InvertString receive receive a text by parameter and display them in reverse order.
Input
radar
Output
radar
Solution
using System;
public class FunctionInvertString
{
public static void Main(string[] args)
{
string text = Console.ReadLine();
string invertString = InvertString(text);
Console.WriteLine(invertString);
}
public static string InvertString(string text)
{
string invertString = string.Empty;
for (int i = text.Length - 1; i >= 0; i--)
{
invertString += text.Substring(i, 1);
}
return invertString;
}
}