Results 1 to 4 of 4

Thread: C++

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Hard Core Gaming HardDrive's Avatar
    Join Date: Jun:2006
    Location:
    Posts: 754

    C++

    , .
    Code:
    //===================== ZeroReverse
    
    // interpolaciq na Lagrange
    
    #include <iostream>
    
    using namespace std;
    
    //=====================
    
    int main()
    {
        
        long double Ap; // promenliva za stoinosta koqto 6te priblijavame (x)
        int s; // razmer na masivite - broi na to4ki
        double x[s]; //masiv za stoinostite na x
        double y[s]; // masiv za stoinostite na y
        int p=s-1; // stepenta na polinoma
        
        cout<<"Input value for x "; cin>>Ap;
        
        cout<<"Input number of elements "; cin>>s;
        
        //podavane na stoinostite  za x
        for(int i=0; i<s; i++)
        {
                cout<<"Input value for x["<<i<<"] "; cin>>x[i];
        }
        
        //podavane na stoinostite za y
        for(int i=0; i<s; i++)
        {       
                cout<<"Input values for y["<<i<<"] "; cin>>y[i];
        }
        
        
        double mn=1; // 
        double del=1; //
        
        
        double sum=0; //
        
        for(int i=0; i<s; i++)
        {
                //cikul za presmqtane na mnojitelite ot tipa (x-x1) etc. v subiraemite 
                for(int q=0; q<=p; q++)
                {
                        int cy=i; // promenliva otbelqzva6ta indeksa na teku6tiq y
                        if(q==cy) continue; // 6te me vru6ta na gorniq cikul ako indeksite na y i x suvpadnat
                        double mn1=(Ap-x[q]); // iz4islqva poredniq mnojitel ot 4islitelq
                        double del1=(x[i]-x[q]); // iz4islqva poredniq mnojitel ot delitelq
                        del=del*del1; // iz4islqva znamenatelq
                        mn=mn*mn1; //iz4islqva 4islitelq
                        
                        
                }
                // sled kraq na toq cikul trqbva da imam 4islitelq i znamenatelq za suotvetnoto subiraemo (opredeleno ot po predhodniq cikul)
                
                
                sum=sum+y[i]*(mn/del);
                
        }
        
        cout<<sum;
                
                
                
                
                
                
                
                
                
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        system("pause");
        return EXIT_SUCCESS;
        
        
    }
    , . , . , Ap double, .


    Code:
    //===================== ZeroReverse
    
    // interpolaciq na Lagrange
    
    #include <iostream>
    
    using namespace std;
    
    //=====================
    
    int main()
    {
        
        long double Ap; // promenliva za stoinosta koqto 6te priblijavame (x)
        int s; // razmer na masivite - broi na to4ki
        double x[s]; //masiv za stoinostite na x
        double y[s]; // masiv za stoinostite na y
        int p=s-1; // stepenta na polinoma
        
        cout<<"Input value for x "; cin>>Ap;
        
        cout<<"Input number of elements "; cin>>s;
        
        //podavane na stoinostite  za x
        for(int i=0; i<s; i++)
        {
                cout<<"Input value for x["<<i<<"] "; cin>>x[i];
        }
        
        //podavane na stoinostite za y
        for(int i=0; i<s; i++)
        {       
                cout<<"Input values for y["<<i<<"] "; cin>>y[i];
        }
        
        
        
        
        
        double temp=1;
        long double sum=0;
        
        for(int i=0; i<s; i++)
        {
                //cikul za presmqtane na mnojitelite ot tipa (x-x1) etc. v subiraemite 
                for(int q=0; q<=p; q++)
                {
                        int cy=i; // promenliva otbelqzva6ta indeksa na teku6tiq y
                        if(q==cy) continue; // 6te me vru6ta na gorniq cikul ako indeksite na y i x suvpadnat
                        temp=temp*((Ap-x[q])/(x[i]-x[q]));
                }
                
                
                
                sum=sum+y[i]*temp;
                
        }
        
        cout<<sum;
                
                
                
                
                
                
                
                
                
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        system("pause");
        return EXIT_SUCCESS;
        
        
    }
    .

    Config: Ryzen 3700x / Gigabyte x570 Gaming X / RX480 Strix 1400@2250 / 2x8gb Corsair Vengeance / Seagate Barracuda 1Tb + 256gb OCZ Trion / SuperFlower Leadex II Gold 750w / BeQuiet B801 / LG 23MA53 + Philips 170c / Logitech G502 / CM QuickFire TK

    Acer Predator G9-593 I7 7700HQ + GTX1070

  2. #2
    ɐ-əpoɔᴉu⋂ ɐ ə anrieff's Avatar
    Join Date: Apr:2004
    Location: Sofia
    Posts: 8,448
    , x[] y[] - .. s, , -.
    , s, .

    Code:
    double x[20];
    double y[20];
    -, 20 .
    , . .
    "640K ught to be enough for anybody" - Bill Gates, 1981
    ::Machine specs::Fract::AGG::::Baileys::blog::YouTube channel

  3. #3
    Hard Core Gaming HardDrive's Avatar
    Join Date: Jun:2006
    Location:
    Posts: 754
    , , s. , .

    - s double mn=1; // double del=1; //, temp . .

    , .
    - .
    !
    Config: Ryzen 3700x / Gigabyte x570 Gaming X / RX480 Strix 1400@2250 / 2x8gb Corsair Vengeance / Seagate Barracuda 1Tb + 256gb OCZ Trion / SuperFlower Leadex II Gold 750w / BeQuiet B801 / LG 23MA53 + Philips 170c / Logitech G502 / CM QuickFire TK

    Acer Predator G9-593 I7 7700HQ + GTX1070

  4. #4
    philosophus duratea icaci's Avatar
    Join Date: Oct:2006
    Location: Aachen
    Posts: 2,698
    new delete:
    Code:
    ...
       s
    ...
    double *x = new double[s];
    double *y = new double[s];
    ...
     x  y    
    ...
    delete [] x;
    delete [] y;
    - , .
    Internet - it doesn't make you stupid, it just makes your stupidity more accessible to others

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 |