desislava_topuzakova

Задача.3. Обръщане на низ

Mar 26th, 2022
1,450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _03._ReversedString
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.            string input = Console.ReadLine(); //"Desi" -> "iseD"
  10.            Console.WriteLine(reverseString(input));
  11.         }
  12.  
  13.         static string reverseString(string text)
  14.         {
  15.             //text = "table";
  16.             string reversedString = ""; //обърнатия текст -> "elbat"
  17.              
  18.             //от последния към първия символ
  19.             for (int position = text.Length - 1; position >= 0; position--)
  20.             {
  21.                 char currentSymbol = text[position];
  22.                 reversedString += currentSymbol;
  23.             }
  24.  
  25.             return reversedString;
  26.         }
  27.     }
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment