Skip to content

Commit 0cddd7e

Browse files
authored
Merge pull request #1 from Jahnavi998/Jahnavi998-patch-1
Create reverse.cs
2 parents 36a7dd6 + cff1bc3 commit 0cddd7e

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Algorithms/Strings/reverse.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
3+
namespace Algorithms.Strings;
4+
5+
public static class ReversedString
6+
{
7+
//comment
8+
// In this Main Method we are taking the input and calling ReverseString Method which will return reversedString and we will print in main Method
9+
//comment
10+
public static void Main(string[] args)
11+
{
12+
// Sample Input : "reverse"
13+
// Sample Output : "esrever"
14+
string input= Console.ReadLine();
15+
string reversedString = ReverseString(input.Trim());
16+
Console.WriteLine(reversedString);
17+
}
18+
19+
//comment
20+
// This Method will take input as string and return the reversed string
21+
//comment
22+
23+
public static string ReverseString (string input)
24+
{
25+
string reverseString="";
26+
int length = input.Length;
27+
while(length!=0)
28+
{
29+
reverseString= reverseString+input[length-1];
30+
length-=1;
31+
}
32+
return reverseString;
33+
}
34+
}

0 commit comments

Comments
 (0)