Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 02. Ascii Sumator
- 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.
- Example
- Input Output
- .
- @
- dsg12gr5653feee5 363
- ?
- E
- @ABCEF 262
- using System;
- public class Program
- {
- public static void Main(string[] args)
- {
- var firstChar = char.Parse(Console.ReadLine());
- var secondChar = char.Parse(Console.ReadLine());
- var randomString = Console.ReadLine();
- var sumChars = 0;
- for (int i = 0; i <= randomString.Length - 1; i++)
- {
- if (randomString[i] > firstChar && randomString[i] < secondChar)
- {
- sumChars += randomString[i];
- }
- }
- Console.WriteLine(sumChars);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment