Results 1 to 25 of 25

Thread: C++

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User Insan3's Avatar
    Join Date: Nov:2009
    Location: Bulgaria
    Posts: 1,119

    Smile C++

    Dev c++, . ( )
    , n n- .


    ( , ) , . !

  2. #2
    ɐ-əpoɔᴉu⋂ ɐ ə anrieff's Avatar
    Join Date: Apr:2004
    Location: Sofia
    Posts: 8,448
    , .
    , . .
    "640K ught to be enough for anybody" - Bill Gates, 1981
    ::Machine specs::Fract::AGG::::Baileys::blog::YouTube channel

  3. #3
    Registered User
    Join Date: Dec:2007
    Location: Sofia
    Posts: 366

  4. #4
    Registered User Insan3's Avatar
    Join Date: Nov:2009
    Location: Bulgaria
    Posts: 1,119
    #include <iostream>
    using namespace std;

    int main()
    {
    int n;

    if(n=0)return 0;
    if(n=1)return 1;
    if(n>1)return n>1;
    else return n=n-1+n-2;
    cout << n << endl;
    system ("pause");
    return 0;
    }

    "", , 1 , system pause.

    , .
    !

  5. #5
    Registered User
    Join Date: Dec:2007
    Location: Sofia
    Posts: 366
    Quote Originally Posted by Insan3 View Post
    , ,

    ( )
    , .
    , , ? n?

  6. #6
    Registered User Insan3's Avatar
    Join Date: Nov:2009
    Location: Bulgaria
    Posts: 1,119
    , - . for (int i=1;i>=n .. Cout-a ,

  7. #7
    Registered User vlex's Avatar
    Join Date: Jan:2008
    Location: Sofia
    Posts: 340
    ... - 2. n3=n2+n1 n1,n2,n3,n4,n5...nn.

  8. #8
    Defender Kaspirtov's Avatar
    Join Date: Jun:2006
    Location: Sf
    Posts: 7,414
    ...

    :
    1) n ...
    cin<<n;

    2) return 0; 0 .. if(n=0)return 0;
    n 0 - ...

    btw, ...

    3) . "arr" n e "" .

    3.1. rr[0] = 0; arr[1] = 1; //10 to ined
    3.2. :
    Code:
    for(int i = 2; i < n; i++)
    {
    arr[i] = arr[i-1] + arr[i-2]; // 1-2?!   
    }
    3.2. O arr[n-1]; /* , */

    4) return 0; - Main() , main(), (.. ) 0.

    : ""?! ...
    Last edited by Kaspirtov; 9th February 2010 at 13:02.
    " , , , , ."

  9. #9
    Registered User idn's Avatar
    Join Date: May:2004
    Location:
    Posts: 491
    Quote Originally Posted by Kaspirtov View Post
    ...

    3) . "arr" n e "" .

    3.1. rr[0] = arr[1] = 0;
    3.2. :
    Code:
    for(int i = 2; i < n; i++)
    {
    arr[i] = arr[i-1] + arr[1-2];
    }
    3.2. O arr[n-1]; /* , */
    , . 3 .
    EP35-DS4 :: Pentium Q9550 :: 4x2GB DDRII :: GeForce 9800GT :: 2x320GB SATA :: DVD-ROM :: CMPSU-450VXEU

  10. #10
    Defender Kaspirtov's Avatar
    Join Date: Jun:2006
    Location: Sf
    Posts: 7,414
    Quote Originally Posted by idn View Post
    , . 3 .

    -.
    " , , , , ."

  11. #11
    ɐ-əpoɔᴉu⋂ ɐ ə anrieff's Avatar
    Join Date: Apr:2004
    Location: Sofia
    Posts: 8,448
    Quote Originally Posted by idn View Post
    , . 3 .
    , , :

    .. a, b - , :

    b = a + b
    a = b - a

    , . .
    "640K ught to be enough for anybody" - Bill Gates, 1981
    ::Machine specs::Fract::AGG::::Baileys::blog::YouTube channel

  12. #12
    read-only jordan17772's Avatar
    Join Date: May:2008
    Location:
    Posts: 3,197


    Code:
       long Fib( int n)
            {
                switch (n)
                {
                    case 0:
                        return 0;
                    case 1:
                    case 2:
                        return 1;
    
                    default:
                        {
                            long a = 1;
                            long b = 2;
                            for (int i = 3; i < n; i++)
                            {
                                long c = a + b;
                                a = b;
                                b = c;
                            }
    
                            return b;
                        }
                }
            }
    n .
    AMD Phenom II X4 980 Black @4GHz with 1.425v |GA-MA790FX-UD5P| Prolimatech Megahalems + Noctua NF-S12B-FLX |EVGA GeForce GTX 1060 SSC 6GB ACX 3.0 | 42GB G.Skill F2-8000CL5D-4GBPQ | 1TB + 640GB WD Black | Seasonic X750 Gold | CM 690 II Advanced Black | Logitech Wave Pro | Edifier R1850DB

  13. #13
    Registered User ined's Avatar
    Join Date: Nov:2006
    Location: Varna
    Posts: 1,078
    , - 0, arr[1] 1
    ASRock B85 Pro4, Pentium G3240, DD3 8GB/1333MHz, 120GB SSD + 1TB + 640GB HDD
    Gigabyte GV-R657OC-1GI, CM B500, ASUS 24B1S1, LCD SAMSUNG SM931BW, 173

  14. #14
    Defender Kaspirtov's Avatar
    Join Date: Jun:2006
    Location: Sf
    Posts: 7,414
    Quote Originally Posted by ined View Post
    , - 0, arr[1] 1
    E -! / - google . , ?!

    , ?! , . - : rr[0] = arr[1] = 0; /* */

    , .

    arr[1-2] - i 1 <- !!!

    - , !

    .. idn, , !
    ..2 anrieff .
    Last edited by Kaspirtov; 9th February 2010 at 13:19.
    " , , , , ."

  15. #15
    read-only jordan17772's Avatar
    Join Date: May:2008
    Location:
    Posts: 3,197
    ,

    var1 = 9 var2 = 4

    1: var1 = var1 + var2 9+4=13

    2: var2 = var1 var2 13-4=9

    3: var1 = var1 var2 13-9=4
    AMD Phenom II X4 980 Black @4GHz with 1.425v |GA-MA790FX-UD5P| Prolimatech Megahalems + Noctua NF-S12B-FLX |EVGA GeForce GTX 1060 SSC 6GB ACX 3.0 | 42GB G.Skill F2-8000CL5D-4GBPQ | 1TB + 640GB WD Black | Seasonic X750 Gold | CM 690 II Advanced Black | Logitech Wave Pro | Edifier R1850DB

  16. #16
    Mes Que Un Club F3N0M3NA's Avatar
    Join Date: Nov:2008
    Location: Sofia
    Posts: 175
    #include <iostream>
    using namespace std;
    int fibona4i (int n) {
    if ((n==1)||(n==2)) return 1;
    return fibona4i(n-2)+fibona4i(n-1);
    }
    int main () {
    int n;
    cout <<"Vuvedete koe 4islo na Fibona4i tursim: ";
    cin >>n;
    cout <<n<<"-toto 4islo na Fibona4i e: "<<fibona4i (n)<<endl;
    system ("pause");
    return 0;
    }
    ,
    Q9550@4.3GHz | 3D Mark 06 GTX 280 | 3D Mark 06 4870x2 | 3D Mark 06 5850
    Asrock P67 Pro3|Intel Core i7 2600k|A-Data 2X2GB DDR3 @ 1866MHz 8-8-8-24|Sapphire 6850|WD Caviar Black 750GB Sata III 64MB|Coolermaster RealPower M700|Coolermaster HAF 922|Samsung SM P2350|A4Tech X755FS|Logitech Wave Keyboard

  17. #17
    Pesho's Avatar
    Join Date: Nov:2001
    Location: Sofia
    Posts: 5,169
    Quote Originally Posted by F3N0M3NA View Post
    ,

    , . O(2^n), O(n).
    , !

  18. #18
    user-friendly 0wn3r's Avatar
    Join Date: Mar:2006
    Location: Bulgaria,Plovdiv
    Posts: 1,165
    Quote Originally Posted by Pesho View Post
    , . O(2^n), O(n).
    , O(log2n) .
    believing

  19. #19
    Banned
    Join Date: Nov:2007
    Location: Sofia
    Posts: 1,400
    Code:
    // Fib.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include <iostream>
    #include <conio.h>
    using namespace std;
    
    long Fib(long x)
    {
    	if (x <= 1)
    		return 1;
    	return Fib(x - 1) + Fib(x - 2);
    }
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	long number = 0;
    	
    	cout << "Enter a number: ";
    	cin >> number;
    
    	cout << "Fib of " << number << " is : " << Fib(number);
    	cout << "\n";
    
    	system("PAUSE");
    }


    Code:
    // Fib.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include <iostream>
    #include <conio.h>
    #include <math.h>
    #include <time.h>
    
    using namespace std;
    
    const long double inverseSqrt5 = 0.44721359549995793928183473374626; 
    const long double phi = 1.6180339887498948482045868343656;
    
    long Fib(long x)
    {
    	if (x <= 1)
    		return 1;
    	return Fib(x - 1) + Fib(x - 2);
    }
    	
    long UltraFastFib(long n) 
    {
        return (int)floor(pow(phi, n) * inverseSqrt5 + 0.5);
    }
    
    long calculate_method(long (*ptr)(long), int number)
    {
    	clock_t start, finish;
    	
    	long result = 0;
    	
    	start = clock();
    	result = (*ptr)(number);
    	finish = clock();
    
    	int seconds = (finish - start)/CLOCKS_PER_SEC;
    
    	cout << "Method took " << seconds << " secodns." << endl;
    
    	return result;
    }
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	long number = 0;
    	
    	
    	cout << "Enter a number: ";
    	cin >> number;
    	
    
    	cout << "Calculating Fib using resursive method ;)"<< endl;
    	cout 
    		<< "Result of fib(" 
    		<< number 
    		<< ") is " 
    		<< calculate_method(&(Fib),number) << endl;
    
    	
    	cout << "Calculating Fib using ultra fast method ;)"<< endl;
    	cout 
    		<< "Result of fib(" 
    		<< number 
    		<< ") is " 
    		<< calculate_method(&(UltraFastFib),number) << endl;
    
    	system("PAUSE");
    }
    Last edited by PhrozenOne; 10th February 2010 at 01:46.

  20. #20
    ɐ-əpoɔᴉu⋂ ɐ ə anrieff's Avatar
    Join Date: Apr:2004
    Location: Sofia
    Posts: 8,448
    Quote Originally Posted by 0wn3r View Post
    , O(log2n) .
    ; , ; , . ( -). , .
    , . .
    "640K ught to be enough for anybody" - Bill Gates, 1981
    ::Machine specs::Fract::AGG::::Baileys::blog::YouTube channel

  21. #21
    Registered User
    Join Date: Sep:2009
    Location:
    Posts: 115
    . , 5-6 .
    :
    Code:
    #include <iostream>
    using namespace std;
    int main()
    {
        int a,n,f=0,g=1,s=0;
        cin>>n;
        
        for(a=0;a<n-1;a++){ s=g; g=g+f; f=s;
                           }
     cout<<s<<"\n";           
    	system("PAUSE");
    }

  22. #22
    Mes Que Un Club F3N0M3NA's Avatar
    Join Date: Nov:2008
    Location: Sofia
    Posts: 175
    Quote Originally Posted by stgram View Post
    . , 5-6 .
    :
    Code:
    #include <iostream>
    using namespace std;
    int main()
    {
        int a,n,f=0,g=1,s=0;
        cin>>n;
        
        for(a=0;a<n-1;a++){ s=g; g=g+f; f=s;
                           }
     cout<<s<<"\n";           
    	system("PAUSE");
    }
    Q9550@4.3GHz | 3D Mark 06 GTX 280 | 3D Mark 06 4870x2 | 3D Mark 06 5850
    Asrock P67 Pro3|Intel Core i7 2600k|A-Data 2X2GB DDR3 @ 1866MHz 8-8-8-24|Sapphire 6850|WD Caviar Black 750GB Sata III 64MB|Coolermaster RealPower M700|Coolermaster HAF 922|Samsung SM P2350|A4Tech X755FS|Logitech Wave Keyboard

  23. #23

    Join Date: Sep:2005
    Location: Sofia
    Posts: 18,517
    , 50- 2^50 .

  24. #24
    The Unknown rager's Avatar
    Join Date: Jul:2004
    Location: Edge Of Darkness
    Posts: 30,360
    ....

  25. #25
    Registered User ined's Avatar
    Join Date: Nov:2006
    Location: Varna
    Posts: 1,078
    Quote Originally Posted by andrejandrej View Post
    . jordan17772 . .
    CODE

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        long long a=0,b=1,c;
        cout<<"Number = ";
        cin >> c;
        while (a<c)
        {
            b=a+b;
            a=b-a;
        }
        cout<<c;
        if (a==c) cout<<" is Fibonacci number";
        cout<<endl;
    }
    ASRock B85 Pro4, Pentium G3240, DD3 8GB/1333MHz, 120GB SSD + 1TB + 640GB HDD
    Gigabyte GV-R657OC-1GI, CM B500, ASUS 24B1S1, LCD SAMSUNG SM931BW, 173

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |