Herzlich Willkommen, lieber Gast!
  Sie befinden sich hier:

  Forum » C / C++ (GNU/Linux, *NIX, *BSD und Co) » GDB Backtrace für rekursive Funktionen

Forum | Hilfe | Team | Links | Impressum | > Suche < | Mitglieder | Registrieren | Einloggen
  Quicklinks: MSDN-Online || STL || clib Reference Grundlagen || Literatur || E-Books || Zubehör || > F.A.Q. < || Downloads   

Autor Thread - Seiten: > 1 <
000
10.11.2014, 16:26 Uhr
huwul



Hallo zusammen,

muss für die Uni als aufgabe 3 rekursive Funktionen mit Variablen Zahlen haben von
GGT, Fakultät und Fibonacci Folge.

Das Programm funktioniert an sich auch wunderbar wie es sollte.

Nun muss ich mir aber mit gdb für jede Rekursionsstufe Backtrace ausgeben lassen und habe mir auch mehrere Tutorials angeschaut und mir einiges durchgelesen allerdings will das einfach nicht klappen.

Ich kann nämlich dabei auch kein Breakpoint in die Funktion setzen.
Und Backtrace gibt dann aus " No Stacks".

Anbei mal die Quelldatei des Programms.


C++:
#include <iostream>
using namespace std;

int erste, zweite, zahl;
int ggT(int erste, int zweite);
int fak(int zahl);
int fib(int zahl);


int main()
{
    int sw, ausgabe;
    cout << " Wählen Sie zwischen: " << endl;
    cout << " 1) Größter gemeinsamer Teiler " << endl;
    cout << " 2) Fakultät " << endl;
    cout << " 3) Fibonacci-Folge " << endl;
    cin >> sw;
    switch(sw)
    {
        case 1: cout << " erste Zahl: " << endl;
            cin >> erste;
            cout << " zweite Zahl: " << endl;
            cin >> zweite;
             ausgabe = ggT(erste, zweite);
            cout << " Ihr Ergebnis ist : " << ausgabe << endl;
            break;

        case 2:    cout << " Geben Sie Ihre Fakultätszahl ein : " << endl;
            cin >> zahl;
            ausgabe = fak(zahl);
            cout << " Ihr Ergebnis ist : " << ausgabe << endl;
            break;
        case 3: cout << " Geben Sie Ihre Fibonaccizahl ein : " << endl;
            cin >> zahl;
            ausgabe = fib(zahl);
            cout << " Ihr Ergebnis ist : " << ausgabe << endl;
            break;
        default: break;
    }




}

int ggT(int erste, int zweite)
{


    if (zweite==0)
    {
        return erste;
    }
    else
    {
        return ggT(zweite, erste%zweite);

    }
}


int fak(int zahl)
{


    if(zahl==0)
    {
        return 1;
    }
    else
    {
        return zahl * fak(zahl-1);

    }
}

int fib(int zahl)
{
    if(zahl==0)
    {
        return 0;
    }
    if(zahl==1)
    {
        return 1;
    }
    else
    {
        return fib(zahl-1)+fib(zahl-2);
    }

}

 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
001
10.11.2014, 16:55 Uhr
FloSoft
Medialer Over-Flow
(Administrator)


doppelpost
--
class God : public ChuckNorris { };
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
Seiten: > 1 <     [ C / C++ (GNU/Linux, *NIX, *BSD und Co) ]  


ThWBoard 2.73 FloSoft-Edition
© by Paul Baecher & Felix Gonschorek (www.thwboard.de)

Anpassungen des Forums
© by Flo-Soft (www.flo-soft.de)

Sie sind Besucher: