đây là code của mình, nhưng làm mãi nó vẫn sai. Mong mọi người thảo luận và giải đáp
#include <iostream>
#include <cstring>
using namespace std;
main()
{
float number;
int extra, c = 0, i = 0, count = 0;
cout << "Enter number: ";
cin >> number; //So can chuyen doi
while(number != int(number))
{
number = number*10;
c++;
} // * lan luot len de thanh mot so nguyen
cout << "C = " << c << endl;
extra = number; //gan cho so nguyen de doi thanh chuoi de hon
cout << "Extra = " << extra << endl;
char *temp = new char[30];
char *result = new char[30];
while(extra > 0) // gan tung phan tu chia duoc vao mang
{
temp[i++] = extra % 10 + '0';
extra = extra / 10;
}
for(int j = i - 1; j >= 0; j--) // in ra mang theo dung thu tu
{
if(count == c)
{
result[count++] = '.'; // gan ky tu '.'
}
else
result[count++] = temp[j];
}
result[count + 1] = '\0';
cout << "\nKq = " << result << endl;
}