473,394 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

writing 6 items in one line.

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.

*
Nov 14 '05 #1
4 1157
Ronen Kfir <ro****@tauex.tau.ac.il> spoke thus:
#include <stdio.h>
void main() ^^^^
Wrong. main() returns int.
{
int i,n=40;
float a=0,b=1;
Why are these floats?
for (i=1;i<=n;i++)
{
printf("%.0f\n",a);
printf("%.0f\n",b);
printf( "%.0f %.0f", a, b );
if( i%3 == 0 )
printf( "\n" );
a+=b;
b+=a;
} getch();
}


Printing the last newline if needed is left as an exercise.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #2
In <b0*************************@posting.google.com> ro****@tauex.tau.ac.il (Ronen Kfir) writes:
#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
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #3
ro****@tauex.tau.ac.il (Ronen Kfir) wrote in message news:<b0*************************@posting.google.c om>...
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.

--
Nick Keighley
Nov 14 '05 #4
ro****@tauex.tau.ac.il (Ronen Kfir) wrote:
Hi,
I have this code:
<snip>
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
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc: http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc OT guide : http://benpfaff.org/writings/clc/off-topic.html
Nov 14 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dot Kom | last post by:
I've got this text file full of lines like: A*1King Richard Dale*3Welton Orchard Rd*4Petersburg*5257-1234Î the columns are defined by the *#, so that line would break apart like: A*1King...
3
by: Raaijmakers, Vincent (IndSys, GE Interlogix) | last post by:
Ok, perhaps a question on a newbie level. I try to create a simple 'write to a console application' where all the items in a string do have a variable size: items = Well, actually, I need to...
4
by: Crypt Keeper | last post by:
I am trying to write a program that asks user for several input items, then takes those items into a class that will manipulate the data and then return a line of output. I am able to input the...
9
by: Cesar A. K. Grossmann | last post by:
Hi I'm trying to build a parser for a file I create. The file format is as follow: IDENTIFIER = NUMBER STRING STRING; COMPOSITE = STRING { ITEM }; ITEM = NUMBER IDENTIFIER|COMPOSITE
10
by: Aaron | last post by:
Hello, I have a small application that I need to save data from 7 text boxes in to a csv file. This will entail btnNext_Click function that will create a new csv file and enter the 7 data fields...
5
by: Stimp | last post by:
I'm populating a dropdown list with non-consecutive values (well the last 3 values are non-consecutive anyway).. What's a shorter way of writing the following?... ddLetMaxPrice.Items.Insert(0,...
21
by: tizmagik | last post by:
Database consists of the following 4 tables with respective attributes: CUSTOMER(C#, CUSTOMER NAME, ADDRESS), the key is ITEM(I#, ITEM NAME, MANUFACTURER, YEAR), the key is BOUGHT(C#, I#,...
19
by: rmr531 | last post by:
First of all I am very new to c++ so please bear with me. I am trying to create a program that keeps an inventory of items. I am trying to use a struct to store a product name, purchase price,...
12
by: hemant.gaur | last post by:
I have an application which writes huge number of bytes into the binary files which is just some marshalled data. int len = Data.size(); //arrary size for (int i = 0; i < len; ++i)...
6
by: kimiraikkonen | last post by:
Hi, I can read from a text file and insert text file's contents into a listbox whose format is line by line using this code: Dim reader As String reader = My.Computer.FileSystem.ReadAllText("c:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.