C code to calculate the binary period of an integer
I see some things that may help you improve your program.  

Use the appropriate #includes

In order to compile and link, this code requires at least #include &lt;stdio.h&gt;.  For the program to be complete, all appropriate #includes should be listed, too.

Check your assumptions

For this code to work, the int on your platform must be at least 32 bits.  For that reason, this assumption should be checked at compile time:

static_assert(sizeof(int) &gt;= 4), "int must be at least 32 bits");


Format your code consistently

It doesn't matter as much what style you use as it matters that you have a consistent style. In particular, there seems to be inconsistent indenting and inconsistent placement of braces.  Using a consistent style helps readers of the code understand it.

Use better variable names

Generally, single letter variable names other than i and j for loop variables, are best avoided in favor of longer, more descriptive names.  The variable p is not too terrible, but the variable l is definitely a poor choice, not least because it's easily mistaken for the digit 1 or the letter i.  I changed it to len in the rewrite I did.

Fix the bug

Right now, if we have the program calculate solution(8), it returns 1 instead of -1.  That is not correct.  There are other values within the range that also return incorrect values.

Write a test program

Right now the main routine just tries three values.  It would be better to try other values, maybe even every value in the range, and test it for accuracy.  You can do that by creating a function bool verify(int n, int p) that returns true if the condition stated at the beginning of the problem is true.