#include <iostream>
using namespace std;
class Code {
int number;
public:
int bin[12] = { 0 };
void initializeData(int n) {
number = n;
}
int getNumber() {
return number;
}
void convertToStarightBinary() {
int q, r, counter = 12;
q = getNumber();
while (q != 0) {
r = q % 2;
q /= 2;
counter--;
bin[counter] = r;
}
}
};
int main() {
Code obj;
int n, i;
cin >> n;
obj.initializeData(n);
obj.convertToStarightBinary();
for (i = 0; i < 12; i++) {
cout << obj.bin[i];
}
return 0;
}
using namespace std;
class Code {
int number;
public:
int bin[12] = { 0 };
void initializeData(int n) {
number = n;
}
int getNumber() {
return number;
}
void convertToStarightBinary() {
int q, r, counter = 12;
q = getNumber();
while (q != 0) {
r = q % 2;
q /= 2;
counter--;
bin[counter] = r;
}
}
};
int main() {
Code obj;
int n, i;
cin >> n;
obj.initializeData(n);
obj.convertToStarightBinary();
for (i = 0; i < 12; i++) {
cout << obj.bin[i];
}
return 0;
}
Test Case 8 fails
ReplyDelete//This code is working
ReplyDelete#include
using namespace std;
class Code
{
int number;
public:
void initializeData(int n)
{
number = n;
}
int convertToStraightBinary()
{
int binaryNum[12];
int i = 0;
while (number > 0)
{
binaryNum[i] = number % 2;
number = number / 2;
i++;
}
FILL:
if (i < 12)
{
binaryNum[i] = 0;
i++;
goto FILL;
}
for (int j = i - 1; j >= 0; j--)
cout << binaryNum[j];
}
};
int main()
{
Code obj;
int n;
cin >> n;
obj.initializeData(n);
obj.convertToStraightBinary();
return 0;
}
Thanks a lot its working!
Delete