Zum Inhalt springen

Der_Code

Mitglieder
  • Gesamte Inhalte

    3
  • Benutzer seit

  • Letzter Besuch

Beiträge von Der_Code

  1. Moin!

    Das Array muss vorher sortiert werden. Ich habe dafür die Funktion sort() benutzt aus der Bibliothek <algorithms>. Man kann dafür auch einen eigenen Bubble-Sort verwenden.

    Hier die Lösung:

    #include <algorithm>
    #define ANZ 100
    using namespace std;
    
    void main(){
      
    int Werte[ANZ];
    int zahl = 0;
    int temp = -1;
    int counter = 0;
    
      sort(Werte, Werte + ANZ);
      
    	for (int i = 0; i < ANZ; i++){
    		zahl = Werte[i];
    		if (temp != zahl){
    			for (int y = 0; y < Anzahl; y++){
    				if (zahl == Werte[y]) counter++;
    			}
    			cout << zahl << " ist " << counter << "x vorhanden." << endl;
    			counter = 0;
    		}
    		temp = zahl;
    	}
    }

    VG,

    Der_Code

Fachinformatiker.de, 2024 by SE Internet Services

fidelogo_small.png

Schicke uns eine Nachricht!

Fachinformatiker.de ist die größte IT-Community
rund um Ausbildung, Job, Weiterbildung für IT-Fachkräfte.

Fachinformatiker.de App

Download on the App Store
Get it on Google Play

Kontakt

Hier werben?
Oder sende eine E-Mail an

Social media u. feeds

Jobboard für Fachinformatiker und IT-Fachkräfte

×
×
  • Neu erstellen...