hailstone seri

i wanna write a program that gets the first number a seri and shows the other:like this
input:4
in this seri the next number comes form the number before it,if that is even
n/2.if that is odd n*3+1
the program have to show this 4 2 1
or this:
input 3:
3 10 5 16 8 4 2 1
i cannot fuiger out what's wrong with my code.
it just prints the last number(1)
any suggettions?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <stdio.h>

int main()
{

     int n,i;

	 scanf("%d",&n);
	 i=n;

	 while(i!=1)
	 {

	     if((i%=2)=0)
		 {
             i=i*3+1;
			 printf("%d\t",i);
		 }
		 else
		 {
             i=i*3+1;
			 printf("%d\t",i);
		 }

     }

     return 0;

}
Last edited on
= is assignment
== is comparison

%= is compound assignment.
i%=2 would be equivalent to i = i%2

So if((i%=2)=0) should be if((i%2)==0)
thanks
Topic archived. No new replies allowed.