Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- начин 1:
- using System;
- namespace _05._Stream_of_letters
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- string text = Console.ReadLine(); //"softuni"
- //всички позиции в текста (0 до последната)
- //повтаряме: взимаме символа на позиция + проверява
- //начало: 0
- //край: дължина - 1
- //промяна: +1
- int sum = 0; //сума от гласните букви
- for (int position = 0; position <= text.Length - 1; position++)
- {
- char symbol = text[position];
- //проверка дали е: a, e, i, o ,u
- if (symbol == 'a')
- {
- sum += 1;
- }
- else if (symbol == 'e')
- {
- sum += 2;
- }
- else if (symbol == 'i')
- {
- sum += 3;
- }
- else if (symbol == 'o')
- {
- sum += 4;
- }
- else if (symbol == 'u')
- {
- sum += 5;
- }
- }
- Console.WriteLine(sum);
- }
- }
- }
- начин 2:
- using System;
- namespace _05._Stream_of_letters
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- string text = Console.ReadLine(); //"softuni"
- //всички позиции в текста (0 до последната)
- //повтаряме: взимаме символа на позиция + проверява
- //начало: 0
- //край: дължина - 1
- //промяна: +1
- int sum = 0; //сума от гласните букви
- for (int position = 0; position <= text.Length - 1; position++)
- {
- char symbol = text[position];
- //проверка дали е: a, e, i, o ,u
- switch (symbol)
- {
- case 'a':
- sum += 1;
- break;
- case 'e':
- sum += 2;
- break;
- case 'i':
- sum += 3;
- break;
- case 'o':
- sum += 4;
- break;
- case 'u':
- sum += 5;
- break;
- }
- }
- Console.WriteLine(sum);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement