I
ivan1994
помогите поставьте плиз коментарии в программе напротив строк . lease:
Код:
#include <iostream>
#include <stdlib>
using namespace std;
char *itos(int, char *, int);
int main(){
char *s = new char[100];
int num, radix;
cout << "num: "; cin >> num;
cout << "radix: "; cin >> radix;
cout << "itoa: " << itoa(num, s, radix) << endl;
cout << "itos: " << itos(num, s, radix) << endl;
delete [] s;
system("pause");
return 0;
}
char *itos(int num, char *s, int radix){
int c = 0;
while (num != 0){
int t = num % radix;
num = num / radix;
if (t < 10) s[c] = (char)(t + '0');
else s[c] = (char)('a' - 10 + t);
c++;
}
for (int i = 0; i < c / 2; i++) swap(s[i], s[c - i - 1]);
return s;
}