LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 03-15-2009, 10:15 PM   #1
guitarstorm
LQ Newbie
 
Registered: Feb 2009
Posts: 5

Rep: Reputation: 0
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?
 
Old 03-15-2009, 11:24 PM   #2
JaksoDebr
Member
 
Registered: Mar 2009
Distribution: Fedora, Slackware
Posts: 104

Rep: Reputation: 21
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Printing man-pages in original format JZL240I-U Linux - General 3 10-26-2010 09:26 AM
Printing Legal format in OO-3 mickeyboa Fedora 1 02-17-2009 03:40 PM
change date format ust Linux - Software 4 01-15-2008 07:43 PM
samba printing format not supported spooge Linux - Networking 4 07-19-2004 11:17 PM
Possible to change the file format..? tarballed Linux - General 4 04-09-2003 03:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration