Visit Jeremy's Blog.
 Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org Trying to change my printing format
 Linux - Newbie This Linux forum is for members that are new to Linux. Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

 03-15-2009, 10:15 PM #1 guitarstorm LQ Newbie   Registered: Feb 2009 Posts: 5 Rep: Trying to change my printing format I'm doing a C Program assignment and i'm supposed to print a size 18 array... But with 3 values on 6 lines... for (i=0; i<17; i++) { printf("%10.4f\t\t\t\n",i); a[i]=(float)(i*i+m)/(float)(2*i+n); } I think there's something wrong with my printf statement... When i run the program, it prints 18 lines in 1 column. How do i change it so i get it to print as 3 columns and 6 rows?
03-15-2009, 11:24 PM   #2
JaksoDebr
Member

Registered: Mar 2009
Distribution: Fedora, Slackware
Posts: 104

Rep:
Your current code only prints out the loop counter, and even that in floating format. It only prints out 17 values, instead of the intended 18 values. The code prints a few tabs without values between them. Value printing happens before the value is calculated, though it isn't used anyway.

Without knowing what your code is supposed to do, I would give it a try like this:

Quote:
 for (i = 0; i < 18; i += 3) { a[i]=(float)(i*i+m)/(float)(2*i+n);(i+1) a[i+1]=(float)((i+1)*(i+1)+m)/(float)(2*(i+1)+n);(i+2) a[i+2]=(float)((i+2)*(i+2)+m)/(float)(2*(i+2)+n); printf("%10.4f\t%10.4f\t%10.4f\n",i, i+1, i+2); }
I haven't compiled it (it's a quick mind hack), but it should print 3 values in a row.

And maybe replace the printf statements input with the array values, instead of the loop counter.

JD

Linux Archive

Last edited by JaksoDebr; 04-02-2009 at 06:15 AM. Reason: additional note

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is Off HTML code is Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post JZL240I-U Linux - General 3 10-26-2010 09:26 AM mickeyboa Fedora 1 02-17-2009 03:40 PM ust Linux - Software 4 01-15-2008 07:43 PM spooge Linux - Networking 4 07-19-2004 11:17 PM tarballed Linux - General 4 04-09-2003 03:12 PM

LinuxQuestions.org

All times are GMT -5. The time now is 11:19 AM.

 Contact Us - Advertising Info - Rules - LQ Merchandise - Donations - Contributing Member - LQ Sitemap -