C# :: Aufgabe #26 :: Lösung #8

11 Lösungen Lösungen öffentlich
#26

Vokale zählen in einem beliebigen Satz

Anfänger - C# von Dome - 28.12.2012 um 23:58 Uhr
Programmieren Sie ein Programm, welches die Anzahl aller Vokale in einem zuvor eingegebenen Satz ausgibt.
Optional wäre die Ausgabe wie oft welcher Vokal in dem Satz vorhanden ist.

Konsolenausgabe:


Geben Sie einen Satz ein :
Dies ist ein toller Satz.
Anzahl der Vokale : 8
A: 1
E: 3
I: 3
O: 1
U: 0
#8
vote_ok
von n.rohde (400 Punkte) - 12.08.2015 um 16:46 Uhr
Quellcode ausblenden C#-Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Vokale_zählen
{
    class Program
    {
        static void Main(string[] args)
        {
            string satz;
            int anzahlA = 0, anzahlE = 0, anzahlI = 0, anzahlO = 0, anzahlU = 0;

            Console.WriteLine("Geben Sie einen Satz ein :");
            satz = Console.ReadLine()+'\0';
            
            for(int i=0;satz[i]!='\0';i++)
            {
                if (satz[i] == 'a')
                    anzahlA++;
                else if (satz[i] == 'e')
                    anzahlE++;
                else if (satz[i] == 'i')
                    anzahlI++;
                else if (satz[i] == 'o')
                    anzahlO++;
                else if (satz[i] == 'u')
                    anzahlU++;
            }
            
            Console.WriteLine("Anzahl der Vokale : " + Convert.ToString(anzahlA + anzahlE + anzahlI + anzahlO + anzahlU));
            Console.WriteLine("A: " + anzahlA);
            Console.WriteLine("E: " + anzahlE);
            Console.WriteLine("I: " + anzahlI);
            Console.WriteLine("O: " + anzahlO);
            Console.WriteLine("U: " + anzahlU);
            Console.Read();
        }
    }
}

Kommentare:

Für diese Lösung gibt es noch keinen Kommentar

Bitte melden Sie sich an um eine Kommentar zu schreiben.
Kommentar schreiben