RE: writing 6 items in one line.

"thoth52" <[email protected]>
Newsgroups gmane.comp.programming.cppug
Message-ID <[email protected]>
If you do NOT want to go to a new line after each number is output, just
remove the newline characters (\n) in your printf statements and add a space
instead.
Then, add a condition at the bottom of each loop. For example, (double-check
this code, I am writing off the top of my head and have not checked it
myself)

if !(i%3) printf("\n");

What you have done:
For each loop, you have printed a pair of numbers, a and b.
If the loop index, i, is divisible by 3, there is no remainder and the
newline character is printed; otherwise, the next pair of numbers is printed
on the same line.

Hope this helps. (Any reason you are using old-style, C, code rather than
C++ code?)

David Binner
[email protected]

 -----Original Message-----
From: Ronen Kfir [mailto:[email protected]]
Sent: Tuesday, April 13, 2004 1:02 PM
To: [email protected]
Subject: [cppug] writing 6 items in one line.
Importance: High



  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.



  R o n e n   K f i r
  System Administrator
  CIT div. Tel Aviv University
  Israel
  Tel: 972-3-6407416
  Fax: 972-3-6405158
  cellular: 972-55-405910
  E-mail: [email protected]






----------------------------------------------------------------------------
--
  Yahoo! Groups Links

    a.. To visit your group on the web, go to:
    http://groups.yahoo.com/group/cppug/

    b.. To unsubscribe from this group, send an email to:
    [email protected]

    c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.