Results 1 to 5 of 5

Thread: 1 (C++)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date: Jan:2009
    Location:
    Posts: 16

    1 (C++)

    !

    , user-a space , , - , ... ?

    !

    #include <iostream>

    char* DEC_OCT(int);

    int main()
    {
    //
    int num;
    std::cout << "Enter a number: ";
    std::cin >> num;
    std::cout << DEC_OCT(num);
    std::cin.get();
    return 0;
    }

    char* DEC_OCT(int dec)
    {
    using namespace std;

    char *rtn;

    int prev, len, temp, *OCT;

    prev = dec;

    for(int i=0;prev!=0;i++)
    {
    prev = prev/8;
    len=i;
    }

    OCT = new int[len+1];

    prev = dec;

    for(int i=0;prev!=0;i++)
    {
    OCT[i] = prev%8;
    prev = prev/8;
    len=i;
    }

    OCT[len+1] = prev%8;
    len++;

    for(int i=0;i<len/2;i++)
    {
    temp=OCT[i];
    OCT[i]=OCT[len-1-i];
    OCT[len-1-i]=temp;
    }

    rtn = new char[len+1];

    for(int i=0;i<len;i++)
    {
    rtn[i]=OCT[i]+'0';
    rtn[i+1]='\0';
    }
    cout<<rtn;
    system ("pause");
    return rtn;
    }

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

    Code:
    while (std::cin >> num) {
    ... //   
    }
    , . .
    "640K ught to be enough for anybody" - Bill Gates, 1981
    ::Machine specs::Fract::AGG::::Baileys::blog::YouTube channel

  3. #3
    Game programmer
    Join Date: Feb:2007
    Location:
    Posts: 1,948
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
        int num = 0;
        while (cin >> num) {
            cout << oct << num << endl;
        }
    }

  4. #4
    Registered User
    Join Date: Jan:2009
    Location:
    Posts: 16
    Quote Originally Posted by Todor032 View Post
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
        int num = 0;
        while (cin >> num) {
            cout << oct << num << endl;
        }
    }
    , 2 ... , !

  5. #5
    ɐ-əpoɔᴉu⋂ ɐ ə anrieff's Avatar
    Join Date: Apr:2004
    Location: Sofia
    Posts: 8,448
    ?
    Code:
    #include <iostream>
    #include <string>
    #include <sstream>
    using namespace std;
    
    
    string OCT(int x)
    {
    	stringstream ss;
    	string result;
    	
    	ss << oct << x;
    	ss >> result;
    	return result;
    }
    
    int main()
    {
        int num = 0;
        while (cin >> num) {
            cout << OCT(num) << endl;
        }
    }
    - OCT - , memory leak-.
    , . .
    "640K ught to be enough for anybody" - Bill Gates, 1981
    ::Machine specs::Fract::AGG::::Baileys::blog::YouTube channel

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 |