FANDOM


  1. include <iostream>
  2. include <cstdlib>
  3. include <cmath>

using namespace std; int silniar (int n); void hanoir(int ik, char a, char b, char c); unsigned int fibr(unsigned int n); unsigned int fibi(unsigned int n); unsigned int fibb(unsigned int n); int main(){

   char wybor;
   do{
   	cout << "1. SILNIA REKURENCJA \n";	
   	cout << "2. SILNIA ITERACJA \n";
   	cout << "3. WIEZA HANOI REKURENCJA \n";
   	cout << "4. WIEZA HANOI ITERACJA \n";
   	cout << "5. CIAG FIBONACCIEGO REKURENCJA \n";
   	cout << "6. CIAG FIBONACCIEGO ITERACJA \n";
   	cout << "7. CIAG FIBONACCIEGO (WZOR BINETA) \n";
       cout << "k) KONIEC \n";
       cin >> wybor;
       switch(wybor){
           case '1':

{

         		int i = silniar(4);
 				cout << i << "\n" ;
 				system ("pause");
         		break;
               }

case '2': { system ("pause"); break; } case '3': { int n;

       		char a,b,c;
      			cout << "wpisz ilosc krazkow: ";
      			cin >> n;
       		hanoir(3, 'A', 'B', 'C');

system ("pause"); break; } case '4': { system ("pause"); break; } case '5': { int i; unsigned int n; cout<<"Podaj liczbe wyrazow ciagu: "; cin>>n; cout<<"\n"; cout<<"Kolejne wyrazy ciagu Fibonacciego wyznaczone iteracyjnie: \n"; cout<<fibr(i)<<"\n"; system ("pause"); break; } case '6': { int i; unsigned int n; cout<<"Podaj liczbe wyrazow ciagu: "; cin>>n; cout<<"\n"; cout<<"Kolejne wyrazy ciagu Fibonacciego wyznaczone iteracyjnie:\n"; for(i=1; i<=n;i++) cout<<fibi(i)<<"\n"; system ("pause"); break; } case '7': {

system ("pause"); break; }

         case 'k': cout << "koniec"; break;
        default: cout << "Wybierz tylko sposrod znakow: f, e, h, k!!!";
       }
       system("cls");
   }while(wybor!='k' && wybor!='K');
   return 0;

} //FUNKCJE int silniar (int n) { if (n<0) return 0; if (n==0 || n==1) return 1; return silniar(n-1)*n; } void hanoir(int n, char A, char B, char C) {

 if (n > 0)
 {
   hanoir(n-1, A, C, B);
   cout << A << " -> " << C << endl;
   hanoir(n-1, B, A, C);
 }

} unsigned int fibr(unsigned int n) {

   if(n == 0) return 0;
   if(n == 1) return 1;
   return fibr(n-1)+fibr(n-2);

} unsigned int fibi(unsigned int n) { unsigned int a=0, b=1; for(unsigned int i=0; i<(n-1); i++) { b += a; a = b-a; } return b; } unsigned int fibb(unsigned int n) {

   return 1.0/sqrt(5.0) * ( pow( (1.0+sqrt(5.0))/2.0 , (double)(n) ) - pow( (1.0-sqrt(5.0))/2.0 , (double)(n) ) );

}

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Więcej z Fandomu

Losowa wiki