diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 6a068ee1..37d364cb 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -49,7 +49,9 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds
GAURAV KUMAR

📖 💻
wboccard

📖 💻
d-l-mcbride

📖 💻 +
Senbagaraman

📖 💻
mihirg008

📖 + diff --git a/Day2/C#/StringReverse.cs b/Day2/C#/StringReverse.cs new file mode 100644 index 00000000..da6fbb58 --- /dev/null +++ b/Day2/C#/StringReverse.cs @@ -0,0 +1,31 @@ +/** + * + * @author: Senbagaraman Manoharan + * @date: 19th October 2020 + * + * Given a string, write a program to return a new string with reversed order of characters + * + * */ +using System; +using System.Collections.Generic; +using System.Reflection; + +public class Program +{ + + public static void Main() + { + string enteredString, rvrString = ""; + int stringLength; + Console.Write("The string to be reversed: "); + enteredString = Console.ReadLine(); + stringLength = enteredString.Length - 1; + while (stringLength >= 0) + { + rvrString = rvrString + enteredString[Length]; + stringLength--; + } + Console.WriteLine("The reversed string is {0}", rvrString); + Console.ReadLine(); + } +} \ No newline at end of file diff --git a/Day2/C#/palindrome.cs b/Day2/C#/palindrome.cs new file mode 100644 index 00000000..3124b84b --- /dev/null +++ b/Day2/C#/palindrome.cs @@ -0,0 +1,41 @@ +/** + * + * @author: Senbagaraman Manoharan + * @date: 19th October 2020 + * + * Given a string, write a funcation which prints whether the given string is palindrome or nor + * + * */ +using System; +using System.Collections.Generic; +using System.Reflection; + +public class Program +{ + + public static void Main() + { + string enteredString, rvrString = ""; + int stringLength; + Console.Write("The string to be checked: "); + enteredString = Console.ReadLine(); + stringLength = enteredString.Length - 1; + while (stringLength >= 0) + { + rvrString = rvrString + enteredString[Length]; + stringLength--; + } + Console.WriteLine("The reversed string is {0}", rvrString); + + if(enteredString.Equals(rvrString)) + { + Console.WriteLine("The given string is palindrome"); + } + else + { + Console.WriteLine("The given string is not palindrome"); + } + + Console.ReadLine(); + } +} \ No newline at end of file diff --git a/Day2/README.md b/Day2/README.md index bf92b3a9..86090d3c 100644 --- a/Day2/README.md +++ b/Day2/README.md @@ -515,7 +515,7 @@ void main(){ ### [reverse.rb](./Ruby/reverse.rb) -```ruby +```c# =begin @author: aaditkamat @date: 22/12/2018 @@ -555,6 +555,47 @@ def long_solution_recursive(str) end ``` + + +## C# Implementation + +### [StringReverse.cs](./C#/StringReverse.cs) + +```c# +/** + * + * @author: Senbagaraman Manoharan + * @date: 19th October 2020 + * + * Given a string, write a program to return a new string with reversed order of characters + * + * */ +using System; +using System.Collections.Generic; +using System.Reflection; + +public class Program +{ + + public static void Main() + { + string enteredString, rvrString = ""; + int stringLength; + Console.Write("The string to be reversed: "); + enteredString = Console.ReadLine(); + stringLength = enteredString.Length - 1; + while (stringLength >= 0) + { + rvrString = rvrString + enteredString[Length]; + stringLength--; + } + Console.WriteLine("The reversed string is {0}", rvrString); + Console.ReadLine(); + } +} +``` + +
## Part B -- Palindrome Check @@ -981,6 +1022,53 @@ public class StringReverseAndPalin { } ``` +## C# implementation + +### [palindrome.cs](./C#/palindrome.cs) +```C# +/** + * + * @author: Senbagaraman Manoharan + * @date: 19th October 2020 + * + * Given a string, write a funcation which prints whether the given string is palindrome or nor + * + * */ +using System; +using System.Collections.Generic; +using System.Reflection; + +public class Program +{ + + public static void Main() + { + string enteredString, rvrString = ""; + int stringLength; + Console.Write("The string to be checked: "); + enteredString = Console.ReadLine(); + stringLength = enteredString.Length - 1; + while (stringLength >= 0) + { + rvrString = rvrString + enteredString[Length]; + stringLength--; + } + Console.WriteLine("The reversed string is {0}", rvrString); + + if(enteredString.Equals(rvrString)) + { + Console.WriteLine("The given string is palindrome"); + } + else + { + Console.WriteLine("The given string is not palindrome"); + } + + Console.ReadLine(); + } +} +``` + ### Have Another solution? The beauty of programming lies in the fact that there is never a single solution to any problem.