Results 1 to 5 of 5
Thread: 1 (C++)
Hybrid View
-
6th December 2010 00:26 #1Registered 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;
}
-
6th December 2010 00:33 #2
Code:while (std::cin >> num) { ... // }, . .
"640K ught to be enough for anybody" - Bill Gates, 1981
::Machine specs::Fract::AGG::::Baileys::blog::YouTube channel
-
6th December 2010 08:11 #3Game 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; } }
-
7th December 2010 01:20 #4
-
7th December 2010 02:48 #5
?
- OCT - , memory leak-.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; } }, . .
"640K ught to be enough for anybody" - Bill Gates, 1981
::Machine specs::Fract::AGG::::Baileys::blog::YouTube channel




Reply With Quote

Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in