writing 6 items in one line.

R

Ronen Kfir

Hi,
I have this code:


#include <stdio.h>
void main()
{
int i,n=40;
float a=0,b=1;
for (i=1;i<=n;i++)
{
printf("%.0f\n",a);
printf("%.0f\n",b);
a+=b;
b+=a;
}

getch();
}

It present Fibonacci serial of 40 elements. Now I need to divide it to
groups of 6 in each row.

Please help me do it.

Cheers.



 
 
D

Dan Pop

In said:
#include <stdio.h>
void main()
{
int i,n=40;
float a=0,b=1;
for (i=1;i<=n;i++)
{
printf("%.0f\n",a);
printf("%.0f\n",b);
a+=b;
b+=a;
}

getch();
}

It present Fibonacci serial of 40 elements. Now I need to divide it to
groups of 6 in each row.

Please help me do it.

No way, until you read the FAQ and modify your program accordingly.

Dan
 
I

Irrwahn Grausewitz

Hi,
I have this code:

It present Fibonacci serial of 40 elements. Now I need to divide it to
groups of 6 in each row.

Please help me do it.

- If you've already learned about the % modulus operator, think
about how it could be used to emit a newline character only
every three loop iterations.

- Otherwise, consider using an auxiliary counter variable in
the loop.

HTH
Regards
 
N

Nick Keighley

I have this code:

#include <stdio.h>
void main()

int main (void)

main() *always* returns int

{
int i,n=40;
float a=0,b=1;
for (i=1;i<=n;i++)
{
printf("%.0f\n",a);
printf("%.0f\n",b);
a+=b;
b+=a;
}

getch();

non-standard call

}

It present Fibonacci serial of 40 elements. Now I need to divide it to
groups of 6 in each row.

maintain a count of how many elements you've printed so far. When it gets
to six print a newline and reset the counter.
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top