gibt es andere möglichkeit...?



  • ich habe das geschrieben ist inordnung aber ich wollte fragen .ob man das zweite funktion in abhängigkeit von zhal schreiben kann?

    #include <cmath>
    #include <iostream>

    using namespace std;

    int main(int argc, char *argv[])
    {
    short zahl;
    short sume;
    cout << "groesse in Bytes" << endl;

    cout << "zahl " << pow(2,sizeof(short) * 8.0 - 1)-1.0 << endl;

    cout << " sume: " << pow(2,sizeof(short) * 8.0 - 1)-1.0 + pow(2,sizeof(short) * 8.0 - 1)-1.0 << endl;

    system("PAUSE");
    return EXIT_SUCCESS;
    }

    diese
    cout << " sume: " << pow(2,sizeof(short) * 8.0 - 1)-1.0 + pow(2,sizeof(short) * 8.0 - 1)-1.0 << endl;

    z.b cout << "sume " << zahl + zahl << endl; // aber zeigt das wert 0 und nicht das richtige

    mfg
    toni



  • c++ code tags - bitte



  • .gibt`S oder nicht?



  • toni733 schrieb:

    diese
    cout << " sume: " << pow(2,sizeof(short) * 8.0 - 1)-1.0 + pow(2,sizeof(short) * 8.0 - 1)-1.0 << endl;

    z.b cout << "sume " << zahl + zahl << endl; // aber zeigt das wert 0 und nicht das richtige

    Hallo Toni,

    meinst Du sowas?

    #include <cmath>
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        short zahl = pow(2,sizeof(short) * 8.0 - 1)-1.0; // besser: zahl = (1 << (sizeof(short) * 8 - 1)) - 1;
        cout << "groesse in Bytes" << endl;
        cout << "zahl " << zahl << endl;
        cout << " sume: " << zahl + zahl << endl;
    
        system("PAUSE");
        return 0;
    }
    

    Gruß
    Werner



  • jetz ist scchon in ordnung 😃


Anmelden zum Antworten