Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Pascalsche Dreieck C++ -- Programm stürzt ab

Empfohlene Antworten

Veröffentlicht

Hi Leute,

wollte mal ein Programm schreiben, welches das Pascalsche Dreieck ausgibt. Nach Eingabe einer Zahl z.B. 5 soll es bis zur fünften Zeile ausgegeben werden.

Hier mal mein Quellqode:

#include <iostream.h>

#include <conio.h>

#include <stdio.h>



int pascal(int zeile, int spalte)

{


	if(spalte == 1 || spalte == zeile)

	{

		return 1;

	}

	else

	{

		return (pascal(spalte -1, zeile -1) + pascal(zeile -1, spalte));

	}


}

int main()

{

	int wert;


	cout<< "Bitte geben Sie eine Zahl bis 5 ein."<<endl;

	cout<< "Wert: "<<endl;

	cin>> wert;


	for(int i=0; i<wert; i++)

	{

		cout<< "\n";


		for(int j=0; j<=i; j++)

		{

			cout<< pascal(i,j)<<"\t";

		}

	}




	getch();

	return 0;	

}

Ich hoffe einer von euch kann mir helfen.

Du musst einen ziemlich alten Compiler am Start haben, dass er diesen Code schluckt.

Auf jeden Fall terminiert deine Rekursion nicht.

Der erste Aufruf ist pascal(0,0), was wiederum pascal(-1, -1) aufruft, was pascal(-2,-2) aufruft, und so weiter. Bis dein Stack überläuft.

Bau mal folgende Zeile am Anfang deiner pascal-Funktion ein, dann siehst du es:

	cout << "Zeile: " << zeile << ", Spalte: " << spalte << "\n";
[/code]

Oder benutz einen Debugger.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.