Originally Posted by
brillpsycho
heres what I have so far. one loop is starting at the end of the 1st instead of into it. ???
If you want that the second loop is inside the first loop than you have to move it into the body of the first:
Code:
for-loop
{
// do stuff
while-loop
{
// do more stuff
}
}
Click_here and poornaMoksha told you already to use braces.
Some more notes:
Code:
printf("enter 2 numbers: ");
scanf("%d%d", &n1, &n2);
for(c=n1;c>=n2;c--)
The program is probably just for yourself but nevertheless here is a bug waiting to happen because you can't be sure that n1 is always bigger than n2.
Code:
while(n1>1)
if(n1%2==0)
{n1=n1/2;
printf("number = %d\n", n1);
i++; }
else
{n1=(n1*3)+1;
printf("number = %d\n", n1);
i++; }
The second and third line in both the if- and the else-body are identical, thus you can move them below:
Code:
while (n1 > 1)
{
if (n1 % 2 == 0)
n1 /= 2;
else
n1 = n1 * 3 + 1;
printf("number = %d\n", n1);
i++;
}
Bye, Andreas