I was wondering if it was possible to have an output in the form of a chart?
Such as;
N T F
1 2 5
4 6 3
2 5 9
If so how is this done?
I was wondering if it was possible to have an output in the form of a chart?
Such as;
N T F
1 2 5
4 6 3
2 5 9
If so how is this done?
Yes it is possible. Here's the sarcastic answer...
But the real answer isn't that much more difficult.Code:#include <stdio.h> int main ( void ) { printf("N\tT\tF\n1\t2\t5\n4\t6\t3\n2\t5\t9\n"); return 0; }
DavT
-----------------------------------------------
How would you use a variable in this?
Code:#include <stdio.h> int main ( void ) { char *chart = "N\tT\tF\n1\t2\t5\n4\t6\t3\n2\t5\t9"; puts(chart); return 0; }
If you understand what you're doing, you're not learning anything.
Say I want to output the equation x+6 into a chart format showing both the x values and the sum.
IE;
X Sum
0 6
1 7
2 8
etc;
Is it possible to do with an array?
It's possible, but you're probably better off building the chart on the fly.
If you understand what you're doing, you're not learning anything.
Like thisHow would you use a variable in this?
And yes you can use arrays but i dont see the need in this example.Code:#include <stdio.h> int main () { int x; int number = 6; int sum; printf("X\tSum\n"); for( x=0; x<20; x++){ sum=x+number; printf("%i\t%i\n",x,sum); } return 0; }
Last edited by GanglyLamb; 10-14-2004 at 10:26 AM.
Originally Posted by Salem
For more versatility (and in my opinion readability), you can place field widths in your printf statement.
That would (for this example) print both x and the sum of x + 6, each with a width of 3 chararacters. So given a simple loop with this statement where x increments through 1-3 would output...Code:printf ("%3d%3d\n", x , x + 6);
Additionally you can fill the whitespace (unused field space) with leading zeros if you wish (defaults to empty spaces). To fill them with 0's it would be,Code:1 7 2 8 3 9
Another simple loop would output...Code:printf ("%03d%03dn", x , x + 6);
If you precede the field width with a - (minus) sign, then the output will be left justified vs the default right justification.Code:001007 002008 003009
Resulting in...Code:printf ("%-3d%-3d\n", x , x + 6);
Code:1 7 2 8 3 9
Last edited by Scribbler; 10-14-2004 at 02:47 PM.
Congradulations. You've managed to get your work done for you without doing anything on your own. You're now officially a leech.
Quzah.
Hope is the first step on the road to disappointment.
But why limit yourself to predefined widths when you can have fun with:For more versatility (and in my opinion readability), you can place field widths in your printf statement.
Code:printf ("%3d%3d\n", x , x + 6);
Code:printf("%*d%*d\n", 3, x, 3, x +6);