Advertisement
desislava_topuzakova

06. Vowels Sum

Jun 25th, 2022
1,167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.79 KB | None | 0 0
  1. начин 1:
  2. using System;
  3.  
  4. namespace _05._Stream_of_letters
  5. {
  6.     internal class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string text = Console.ReadLine(); //"softuni"
  11.             //всички позиции в текста (0 до последната)
  12.  
  13.             //повтаряме: взимаме символа на позиция + проверява
  14.             //начало: 0
  15.             //край: дължина - 1
  16.             //промяна: +1
  17.  
  18.             int sum = 0; //сума от гласните букви
  19.             for (int position = 0; position <= text.Length - 1; position++)
  20.             {
  21.                 char symbol = text[position];
  22.                 //проверка дали е: a, e, i, o ,u
  23.  
  24.                 if (symbol == 'a')
  25.                 {
  26.                     sum += 1;
  27.                 }
  28.                 else if (symbol == 'e')
  29.                 {
  30.                     sum += 2;
  31.                 }
  32.                 else if (symbol == 'i')
  33.                 {
  34.                     sum += 3;
  35.                 }
  36.                 else if (symbol == 'o')
  37.                 {
  38.                     sum += 4;
  39.                 }
  40.                 else if (symbol == 'u')
  41.                 {
  42.                     sum += 5;
  43.                 }
  44.             }
  45.  
  46.             Console.WriteLine(sum);
  47.  
  48.  
  49.         }
  50.     }
  51. }
  52.  
  53. начин 2:
  54. using System;
  55.  
  56. namespace _05._Stream_of_letters
  57. {
  58.     internal class Program
  59.     {
  60.         static void Main(string[] args)
  61.         {
  62.             string text = Console.ReadLine(); //"softuni"
  63.             //всички позиции в текста (0 до последната)
  64.  
  65.             //повтаряме: взимаме символа на позиция + проверява
  66.             //начало: 0
  67.             //край: дължина - 1
  68.             //промяна: +1
  69.  
  70.             int sum = 0; //сума от гласните букви
  71.             for (int position = 0; position <= text.Length - 1; position++)
  72.             {
  73.                 char symbol = text[position];
  74.                 //проверка дали е: a, e, i, o ,u
  75.  
  76.                 switch (symbol)
  77.                 {
  78.                     case 'a':
  79.                         sum += 1;
  80.                         break;
  81.                     case 'e':
  82.                         sum += 2;
  83.                         break;
  84.                     case 'i':
  85.                         sum += 3;
  86.                         break;
  87.                     case 'o':
  88.                         sum += 4;
  89.                         break;
  90.                     case 'u':
  91.                         sum += 5;
  92.                         break;
  93.                 }
  94.             }
  95.  
  96.             Console.WriteLine(sum);
  97.  
  98.  
  99.         }
  100.     }
  101. }
  102.  
  103.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement