Teh first term is 1, the second term is 2, and for all n>=3 the nth term is equal to term (n-1) plus term n/2, where n/2 is rounded down.
Program should prompt for n, and then display the nth term in the sequence. it can be assumed n is 50 or less. the program must contain a loop that keeps reading new values for n and then prints the nth term. The program show stop when n=0.
Code://tj wright 11.1 #include <stdio.h> void main (void) { int q,m,n,x[50]; for (m=1;m<=6;m++) { printf("enter n"); scanf ("%d", &n); if (n==0) goto end; x[1]=1; x[2]=2; for (q=3;q<=50;q++) { x[q]=x[q-1]=x[q/2]; } printf("The number is %d\n",x[n]); } end: }
When I run the program, it asks me to enter n, then I go to scan it in, and the program exits and points me to the x[2]=2; line. I am trying to trace the program and see where it is going wrong, but I cannot tell.
Can anyone tell me where I am going wrong?