Advertisement
Cinder1986

Lab18-3

Mar 26th, 2023
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.67 KB | None | 0 0
  1. namespace ConsoleApp1
  2. {
  3.     class Program
  4.     {
  5.         static string excludeEachNSymbol(string line, int N)
  6.         {
  7.             string cutLine = string.Empty;
  8.             for (int i = 0; i < line.Length; i++)
  9.                 if ((i + 1) % N != 0)
  10.                     cutLine += line[i];
  11.             return cutLine;
  12.         }
  13.  
  14.         static void Main(string[] args)
  15.         {
  16.             Console.Write("Enter a line: ");
  17.             string line = Console.ReadLine();
  18.             if (line.Length % 2 == 0)
  19.                 Console.Write(excludeEachNSymbol(line, 2));
  20.             else
  21.                 Console.Write("The string is of odd length.");
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement