Please, can anyone help switch this to c++?
I will be very grateful!
#include %26lt;stdio.h%26gt;
/* Computes the length of Collatz sequences */
unsigned int step (unsigned int x)
{
if (x % 2 == 0)
{
return (x / 2);
}
else
{
return (3 * x + 1);
}
}
unsigned int nseq (unsigned int x0)
{
unsigned int i = 1, x;
if (x0 == 1 || x0 == 0)
return i;
x = step (x0);
while (x != 1 %26amp;%26amp; x != 0)
{
x = step (x);
i++;
}
return i;
}
int main (void)
{
unsigned int i, m = 0, im = 0;
for (i = 1; i %26lt; 500000; i++)
{
unsigned int k = nseq (i);
if (k %26gt; m)
{
m = k;
im = i;
printf ("sequence length = %u for %u\n", m, im);
}
}
return 0;
}
How to change from c to c++?
if u know c++
then change few input output statement and techniques of programming
Reply:You have the pseudo code and the C code from this and other posts I see. You should be able to do this. Your degree will mean nothing if you dont know how to program! Now put your nose to the grind and learn!
Reply:Or else you may contact a C++ expert at websites like http://oktutorial.com/
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment