.....

G

gew

int main(void)
{
int i[5] = { 16,56,124,54,511};
int j,k=1,l;
for(j=0;j>=0;k*=7,j+=k)
{
for(l=i[j];l>0;l>>=1)
{
putchar(l&1?'*':' ');
}
putchar(('\n'*01));
}
return 0;
}
 
I

Ike Naar

Don't forget to #include said:
int main(void)
{
int i[5] = { 16,56,124,54,511};

You can leave out the number ``5''. The compiler will automatically
determine the correct size of the array.
int j,k=1,l;
for(j=0;j>=0;k*=7,j+=k)
{
for(l=i[j];l>0;l>>=1)
{
putchar(l&1?'*':' ');
}
putchar(('\n'*01));

What's the purpose of the ``*01'' ?
}
return 0;
}

The main problem (apart from the minor points mentioned above)
with this program is that is has undefined behaviour, because
you're reading an array outside its bounds. On my computer, the program
crashes almost immediately. Also, the assignment ``k*=7'' overflows
after a few iterations. The output becomes much more interesting if
you declare j and k as ``unsigned'', and replace the last assignment
in the control part of the outer for loop:

by

j = (j + k) % (sizeof i / sizeof *i)
 
K

Kenny McCormack

Don't forget to #include said:
int main(void)
{
int i[5] = { 16,56,124,54,511};

You can leave out the number ``5''. The compiler will automatically
determine the correct size of the array.

Really? So, it should be:

int i[] = { 16,6,124,4,11};

?
 
B

BartC

Ike Naar said:
Don't forget to #include said:
int main(void)
{
int i[5] = { 16,56,124,54,511};

You can leave out the number ``5''. The compiler will automatically
determine the correct size of the array.

Unless you make a mistake in the list of numbers. (Although I think only too
many numbers are picked up as an error, not too few.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,201
Latest member
KourtneyBe

Latest Threads

Top