Autor Wiadomość
Ricko
PostWysłany: Śro 12:33, 13 Mar 2013    Temat postu: STUDIA: NWD Rekurencyjnie

Cytat:
#include <cstdlib>
#include <iostream>

using namespace std;

int rek (int c, int d)
{
if (c == d) return c;
else
if (c > d) return rek(c-d,d);
else return rek(c,d-c);
}

int main(int argc, char *argv[])
{
int a,b;
cout<<"Program rekurencyjny do NWD"<<endl;
cout<<"Podaj dwie liczby"<<endl;
cout<<"a=";
cin>>a;
cout<<"b=";
cin>>b;
cout<<"NWD wynosi "<<rek(a,b)<<endl; /*Wywolywanie funkcji z parametrami a i b*/

system("PAUSE");
return EXIT_SUCCESS;
}

Powered by phpBB © 2001,2002 phpBB Group