# Thread: Help needed on this !!!!

1. ## Help needed on this !!!!

I need help on this.can someone help me tell me what the code is talking about and how to tackle this problem ...the code is suppose to output this .............

[OUTPUT]

Sample outputs
\$ a.out
Enter a number at most equal to 1023: 0
Cycling through {}
yields {}.
\$ a.out
Enter a number at most equal to 1023: 4
Cycling through {2}
yields {3}.
\$ a.out
Enter a number at most equal to 1023: 512
Cycling through {9}
yields {0}.
\$ a.out
Enter a number at most equal to 1023: 5
Cycling through {0, 2}
yields {1, 3}.
\$ a.out
Enter a number at most equal to 1023: 530
Cycling through {1, 4, 9}
yields {0, 2, 5}.
\$ a.out
Enter a number at most equal to 1023: 85
Cycling through {0, 2, 4, 6}
yields {1, 3, 5, 7}.
\$ a.out
Enter a number at most equal to 1023: 408
Cycling through {3, 4, 7, 8}
yields {4, 5, 8, 9}.
\$ a.out
Enter a number at most equal to 1023: 682
Cycling through {1, 3, 5, 7, 9}
yields {0, 2, 4, 6, 8}.

[/OUTPUT]

This is the code .
Code:
```#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>

int cycle(int);
void display_set_coded_by(int);

int main(void) {
int n;
printf("Enter a number at most equal to 1023: ");
scanf("%d", &n);
printf("Cycling through ");
display_set_coded_by(n);
printf("\n         yields ");
display_set_coded_by(cycle(n));
puts(".");
return EXIT_SUCCESS;
}

void display_set_coded_by(int n) {
printf("{");
bool digits_found = false;
for (int i = 0; i < 10; ++i)
if (n & 1 << i) {
printf("%d, ", i);
digits_found = true;
}
if (digits_found)
printf("\b\b");
putchar('}');
}

int cycle(int n) {
/* ... REPLACE THIS COMMENT WITH YOUR CODE ..```

2. Originally Posted by code_lover
I need help on this.can someone help me tell me what the code is talking about and how to tackle this problem ...the code is suppose to output this .............
Code:
```int cycle(int n) {
/* ... REPLACE THIS COMMENT WITH YOUR CODE ..```
That part is the code they are talking about.

Quzah.

3. Thx for looking at the code,i understand thats the area i need to modify.

i need help understand this ....

Code:
```
void display_set_coded_by(int n) {
printf("{");
bool digits_found = false;
for (int i = 0; i < 10; ++i)
if (n & 1 << i) {
printf("%d, ", i);
digits_found = true;
}
if (digits_found)
printf("\b\b");
putchar('}');```

4. I have look at that !!!.
i don,t understand how this function
Code:
`  display_set_coded_by(cycle(n))`
is displaying a that yield output.
thx

5. Till you figure out the right thing to do just return n inside cycle.
Code:
```int cycle(int n) {
return n;
}```
Input this series of numbers (just one each time)
1,2,4,8,16,32,64,128,256,512

What is the output?

You should notice a pattern and having read how bit-wise operators work should understand the next step.
Edit: if you do not see a pattern write down the input numbers in binary form and it should be easier to see the pattern.

Note: remember "Enter a number at most equal to 1023" means that the largest value allowed returned by cycle is 1023.

Tim S.

6. I have tried reading bit-wise operators but don,t still get it.
I have written down all these series of number down (1,2,4,8,16,32,64,128,256,512) but i don,t understand much...the only thing i understood with the binary forms of those numbers are their 1s keep on shifting left side 1.

7. So are they supposed to be reverse engineering the output to figure out what the function does (in which case it does us absolutely no good to help you), or do you actually have a description of your problem?

Quzah.

8. i appreciate your efforts in helping me ...is not that easy and clear because i m very very new to programming and i need to fix this a early as possible to help me continue with my project.

9. So answer my question. Did they give you a description of the project, or are you supposed to work out on your own what the function does given a specific input, based purely on the output you see?

Quzah.

10. i was only given that output and the code to modify it.its very confusing to me.

11. Code:
```Enter a number at most equal to 1023: 85
Cycling through {0, 2, 4, 6}
yields {1, 3, 5, 7}.```
Look at the number 85 as binary..
What does it have in common with the first line of output?
Use that to try and figure out what the second line of output means.
Use all of the above to figure out how to turn 85 to (that number). Hint: think about what the function name cycle() might mean in this context.