JulianJulianov

15.TextProcessingMoreExercise-Ascii Sumator

Apr 23rd, 2020
667
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. 02. Ascii Sumator
  2. Write a program that prints a sum of all characters between two given characters (their ascii code). On the first line you will get a character. On the second line you get another character. On the last line you get a random string. Find all the characters between the two given and print their ascii sum.
  3. Example
  4. Input                             Output
  5. .
  6. @
  7. dsg12gr5653feee5                  363
  8. ?
  9. E
  10. @ABCEF                            262
  11.  
  12. using System;
  13.                    
  14. public class Program
  15. {
  16.      public static void Main(string[] args)
  17.      {
  18.             var firstChar = char.Parse(Console.ReadLine());
  19.             var secondChar = char.Parse(Console.ReadLine());
  20.             var randomString = Console.ReadLine();
  21.  
  22.             var sumChars = 0;
  23.             for (int i = 0; i <= randomString.Length - 1; i++)
  24.             {
  25.                 if (randomString[i] > firstChar && randomString[i] < secondChar)
  26.                 {
  27.                     sumChars += randomString[i];
  28.                 }
  29.             }
  30.             Console.WriteLine(sumChars);
  31.      }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment