Someone experienced in C language can help me translate this code in B4A?
I tried but my code does not work.
Thank you
// Factorize 'value' and save result in 'res'
void factorize(char*res, int value)
{
res[0] ='\0';
if (is_prime(value))
{
sprintf(res, "%d", value);
return;
}
for (int i =2; value >1&& i <= value; ++i)
{
if (!is_prime(i)) continue;
int exp;
for (exp =0; value%i==0; value/=i, ++exp);
if (!exp) continue;
if (exp >1) sprintf(res, "%s%d^%d", res, i, exp);
else sprintf(res, "%s%d", res, i);
if (value >1) sprintf(res, "%s * ", res);
}
return;
}
bool is_prime(int value)
{
for (int i =2; i <= sqrt(value); ++i)
if (value%i==0) returnfalse;
returntrue;
}
I tried but my code does not work.
Thank you
// Factorize 'value' and save result in 'res'
void factorize(char*res, int value)
{
res[0] ='\0';
if (is_prime(value))
{
sprintf(res, "%d", value);
return;
}
for (int i =2; value >1&& i <= value; ++i)
{
if (!is_prime(i)) continue;
int exp;
for (exp =0; value%i==0; value/=i, ++exp);
if (!exp) continue;
if (exp >1) sprintf(res, "%s%d^%d", res, i, exp);
else sprintf(res, "%s%d", res, i);
if (value >1) sprintf(res, "%s * ", res);
}
return;
}
bool is_prime(int value)
{
for (int i =2; i <= sqrt(value); ++i)
if (value%i==0) returnfalse;
returntrue;
}